#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll psum[100005];
ll sm[100005];
ll b;
int r;
ll range(int r, int l) {
return psum[r] - psum[l - 1];
}
bool one(int k) {
if(k == 1) return true;
for(int i = 1; i + k - 1 <= r; i++) {
int m = i + k / 2;
ll lef = m - i;
ll rig = k - lef;
ll sum = (sm[m] * lef - range(m - 1, i)) + (range(i + k - 1, m) - sm[m] * rig);
if(sum <= b) return true;
}
return false;
}
int besthub(int R, int L, int x[], ll B) {
b = B; r = R;
for(int i = 1; i <= r; i++) {
psum[i] = psum[i - 1] + x[i - 1];
sm[i] = x[i - 1];
//cerr << psum[i] << '\n';
}
int l = 1, rr = r;
while(l < rr) {
int m = (l + rr + 1) / 2;
if(one(m)) l = m;
else rr = m - 1;
}
return l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
300 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
304 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
716 KB |
Output is correct |
2 |
Correct |
4 ms |
716 KB |
Output is correct |
3 |
Correct |
16 ms |
3272 KB |
Output is correct |
4 |
Correct |
18 ms |
3188 KB |
Output is correct |
5 |
Correct |
8 ms |
1612 KB |
Output is correct |
6 |
Correct |
8 ms |
1572 KB |
Output is correct |
7 |
Correct |
13 ms |
3020 KB |
Output is correct |
8 |
Correct |
13 ms |
2920 KB |
Output is correct |
9 |
Correct |
7 ms |
1484 KB |
Output is correct |
10 |
Correct |
7 ms |
1484 KB |
Output is correct |
11 |
Correct |
16 ms |
3268 KB |
Output is correct |
12 |
Correct |
15 ms |
3276 KB |
Output is correct |
13 |
Correct |
8 ms |
1612 KB |
Output is correct |
14 |
Correct |
8 ms |
1612 KB |
Output is correct |
15 |
Correct |
11 ms |
2508 KB |
Output is correct |
16 |
Correct |
13 ms |
2516 KB |
Output is correct |
17 |
Correct |
13 ms |
2892 KB |
Output is correct |
18 |
Correct |
14 ms |
2928 KB |
Output is correct |
19 |
Correct |
20 ms |
3048 KB |
Output is correct |
20 |
Correct |
16 ms |
3148 KB |
Output is correct |