Submission #753299

# Submission time Handle Problem Language Result Execution time Memory
753299 2023-06-05T02:53:16 Z acceptify Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 2388 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int X[], long long B){
    long long ps[R];
    for (int i = 0; i < R; i++) ps[i] = X[i] + (i ? ps[i - 1] : 0);
    auto calc = [&] (long long l, long long r, long long p) -> long long {
        long long sum = 0;
        sum += X[p] * (p - l + 1) - ps[p] + (l ? ps[l - 1] : 0LL);
        sum += ps[r] - ps[p] - X[p] * (r - p);
        return sum;
    };
    int l = 0, r = R, res = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        long long cost = 1e18;
        for (int i = 0; i + mid - 1 < R; i++) {
            int p = (i + i + mid - 1) / 2;
            cost = min(cost, calc(i, i + mid - 1, p));
        }
        if (cost <= B) l = mid + 1, res = mid;
        else r = mid - 1;
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 468 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 16 ms 1468 KB Output is correct
4 Correct 12 ms 1364 KB Output is correct
5 Correct 8 ms 852 KB Output is correct
6 Correct 7 ms 852 KB Output is correct
7 Correct 10 ms 1468 KB Output is correct
8 Correct 9 ms 1364 KB Output is correct
9 Correct 6 ms 900 KB Output is correct
10 Correct 6 ms 852 KB Output is correct
11 Correct 11 ms 1492 KB Output is correct
12 Correct 11 ms 1364 KB Output is correct
13 Correct 7 ms 980 KB Output is correct
14 Correct 8 ms 1228 KB Output is correct
15 Correct 15 ms 1868 KB Output is correct
16 Correct 9 ms 1860 KB Output is correct
17 Correct 11 ms 2256 KB Output is correct
18 Correct 12 ms 2260 KB Output is correct
19 Correct 11 ms 2328 KB Output is correct
20 Correct 11 ms 2388 KB Output is correct