#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int besthub(int R, int L, int X[], long long B) {
const int n = R;
vector<ll> pre(X, X+n);
for (int i = 1; i < n; ++i) pre[i] += pre[i-1];
auto sum = [](const vector<ll>& ps, int l, int r)->long long{
if (l > r) return 0LL;
ll ans = ps[r];
if (l > 0) ans -= ps[l-1];
return ans;
};
auto get = [&sum](int l, int r, const vector<ll>& ps, int a[], ll p)->long long{
int idx = upper_bound(a, a+r+1, p) - a;
int g = max(0, 1+r-idx);
int le = max(0, idx-l);
return p*1LL*le-sum(ps,l,idx-1)+sum(ps,idx,r)-1LL*g*p;
};
auto cost = [&get, &sum](int l, int r, const vector<ll>& ps, int a[])->long long{
long long av = sum(ps, l, r)/ll(1+r-l);
return min({get(l, r, ps, a, av-1), get(l, r, ps, a, av), get(l, r, ps, a, 1+av)});
};
int ans = 1;
for (int i = 0; i < n; ++i) {
int low = i, high = n-1, best = -1;
while (low <= high) {
int mid = (low+high) >> 1;
if (cost(i,mid,pre,X) <= B) {
low = 1+mid;
best = mid;
} else {
high = mid-1;
}
}
assert(best >= i && best < n);
ans = max(ans, 1+best-i);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
376 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
0 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
256 KB |
Output is correct |
17 |
Correct |
1 ms |
256 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
1 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
256 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
256 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
2 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
9 ms |
512 KB |
Output is correct |
22 |
Correct |
9 ms |
384 KB |
Output is correct |
23 |
Correct |
9 ms |
384 KB |
Output is correct |
24 |
Correct |
9 ms |
384 KB |
Output is correct |
25 |
Correct |
10 ms |
384 KB |
Output is correct |
26 |
Correct |
8 ms |
384 KB |
Output is correct |
27 |
Incorrect |
9 ms |
512 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
640 KB |
Output is correct |
2 |
Correct |
34 ms |
640 KB |
Output is correct |
3 |
Correct |
288 ms |
2560 KB |
Output is correct |
4 |
Correct |
283 ms |
2552 KB |
Output is correct |
5 |
Correct |
130 ms |
1280 KB |
Output is correct |
6 |
Correct |
131 ms |
1280 KB |
Output is correct |
7 |
Correct |
220 ms |
2304 KB |
Output is correct |
8 |
Correct |
241 ms |
2304 KB |
Output is correct |
9 |
Correct |
126 ms |
1152 KB |
Output is correct |
10 |
Correct |
131 ms |
1152 KB |
Output is correct |
11 |
Correct |
275 ms |
2688 KB |
Output is correct |
12 |
Correct |
273 ms |
2560 KB |
Output is correct |
13 |
Incorrect |
111 ms |
1280 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |