Beispiel #1
0
 public void solve(int testNumber, FastReader in, PrintWriter out) {
   int n = in.nextInt();
   int[] len = new int[n];
   for (int i = 0; i < n; ++i) {
     len[i] = in.nextInt();
   }
   double lr = 0;
   double rr = 1e6;
   for (int it = 0; it < 50; ++it) {
     double r = (lr + rr) / 2;
     double[] dp = new double[n + 1];
     boolean ok = true;
     for (int i = 0; i < n; ++i) {
       int l = len[i];
       double mn = Math.abs(dp[i] - l);
       if (mn > r + EPS) {
         ok = false;
         break;
       }
       double mx = Math.min(r, dp[i] + l);
       dp[i + 1] = mx;
     }
     if (ok) {
       rr = r;
     } else {
       lr = r;
     }
   }
   out.printf(LOCALE, "%.15f\n", (lr + rr) / 2);
 }
Beispiel #2
0
 public void solve(int testNumber, FastReader in, FastWriter out) {
   int n = in.nextInt();
   int m = in.nextInt();
   int[] a = new int[n];
   a[0] = in.nextInt();
   for (int i = 1; i < n; i++) {
     a[i] = (23 * a[i - 1] + 21563) % 16714589;
   }
   SparseTableMin table = new SparseTableMin(a);
   int u = in.nextInt();
   int v = in.nextInt();
   for (int i = 1; i < m; i++) {
     int ans = table.getMin(Math.min(u, v) - 1, Math.max(u, v));
     int newU = (17 * u + 751 + ans + 2 * i) % n + 1;
     int newV = (13 * v + 593 + ans + 5 * i) % n + 1;
     u = newU;
     v = newV;
   }
   out.println(u + " " + v + " " + table.getMin(Math.min(u, v) - 1, Math.max(u, v)));
 }
 public void solve(int testNumber, FastReader in, FastWriter out) {
   int n = in.nextInt();
   int[] p = in.nextArrayInt(n);
   List<BigInteger>[] poly = new List[n];
   for (int i = 0; i < n; i++) {
     poly[i] = new ArrayList<>();
     int size = in.nextInt() + 1;
     for (int j = 0; j < size; j++) {
       poly[i].add(BigInteger.valueOf(in.nextInt()));
     }
     Collections.reverse(poly[i]);
   }
   Set<Integer>[] g = new Set[n];
   for (int i = 0; i < n; i++) {
     g[i] = new HashSet<>();
   }
   int edges = in.nextInt();
   for (int i = 0; i < edges; i++) {
     g[in.nextInt() - 1].add(in.nextInt() - 1);
   }
   int pS = 0;
   for (int i = 0; i < n; i++) {
     pS += p[i];
   }
   BigInteger fmax = BigInteger.ZERO;
   boolean[] used = new boolean[n];
   int[] ans = new int[n];
   for (int it = 0; it < n; ++it) {
     int job = -1;
     BigInteger cur = null;
     for (int i = 0; i < n; ++i) {
       if (!used[i] && g[i].isEmpty()) {
         BigInteger now = eval(poly[i], pS);
         if (job < 0 || cur.compareTo(now) > 0) {
           job = i;
           cur = now;
         }
       }
     }
     assert (job >= 0);
     fmax = fmax.max(cur);
     used[job] = true;
     pS -= p[job];
     ans[job] = pS;
     for (int i = 0; i < n; ++i) {
       g[i].remove(job);
     }
   }
   out.println(fmax);
   out.printArray(ans);
 }