#include "ricehub.h"
#include <vector>
#include <algorithm>
#include <climits>
#include <iostream>
int besthub(int R, int L, int X[], long long B)
{
int ans = 0;
std :: vector<long long> pre(R + 1, 0);
for(int i = 1; i <= R; ++i) pre[i] = pre[i - 1] + X[i - 1];
for(int i = 0; i < R; ++i) {
int lo = 0;
for(int k = 31 - __builtin_clz(R); k >= 0; --k) {
int n = lo | (1 << k);
int mid = (n - 1) / 2;
if(i - mid < 0 || i + mid >= R) continue;
auto l = pre[i] - pre[i - mid];
auto r = pre[i + mid + 1] - pre[i + 1];
if(n & 1) {
if(r - l <= B) lo = n;
} else {
if(i + mid + 1 < R && r + X[i + mid + 1] - l - X[i] <= B) lo = n;
if(i - mid - 1 >= 0 && r - l - X[i - mid - 1] + X[i] <= B) lo = n;
}
}
ans = std :: max(ans, lo);
}
return ans;
}
# |
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 |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
272 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
300 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 ms |
204 KB |
Output is correct |
24 |
Correct |
0 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 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 |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
208 KB |
Output is correct |
18 |
Correct |
0 ms |
208 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 |
292 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 |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
296 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
460 KB |
Output is correct |
2 |
Correct |
4 ms |
572 KB |
Output is correct |
3 |
Correct |
20 ms |
2468 KB |
Output is correct |
4 |
Correct |
20 ms |
2472 KB |
Output is correct |
5 |
Correct |
11 ms |
1204 KB |
Output is correct |
6 |
Correct |
10 ms |
1200 KB |
Output is correct |
7 |
Correct |
19 ms |
2192 KB |
Output is correct |
8 |
Correct |
19 ms |
2128 KB |
Output is correct |
9 |
Correct |
10 ms |
1076 KB |
Output is correct |
10 |
Correct |
10 ms |
1076 KB |
Output is correct |
11 |
Correct |
20 ms |
2456 KB |
Output is correct |
12 |
Correct |
20 ms |
2480 KB |
Output is correct |
13 |
Correct |
12 ms |
1332 KB |
Output is correct |
14 |
Correct |
12 ms |
1228 KB |
Output is correct |
15 |
Correct |
15 ms |
1840 KB |
Output is correct |
16 |
Correct |
15 ms |
1952 KB |
Output is correct |
17 |
Correct |
18 ms |
2248 KB |
Output is correct |
18 |
Correct |
18 ms |
2244 KB |
Output is correct |
19 |
Correct |
20 ms |
2336 KB |
Output is correct |
20 |
Correct |
20 ms |
2404 KB |
Output is correct |