#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
long long sum[N];
long long min(long long a, int b) { return a < b ? a : b; }
int besthub(int R, int L, int X[], long long B)
{
for(int i = 1; i <= R; i++) sum[i] = sum[i - 1] + X[i - 1];
int res = 0;
int l = 0, r = R;
while(l <= r) {
int mid = (l + r) >> 1;
int m = mid >> 1;
long long ret = LLONG_MAX;
for(int i = 1; i <= R - mid + 1; i++) {
if(mid == 1) ret = min(ret, 0);
if(mid == 2) ret = min(ret, X[i] - X[i - 1]);
else {
long long t = sum[i + mid - 1] - sum[i + m] - sum[i + m - 1] + sum[i - 1];
if(mid & 1) ret = min(ret, t);
else ret = min(ret, t + X[i + m - 1]);
}
}
if(ret <= B) res = mid, l = mid + 1;
else r = mid - 1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
252 KB |
Output is correct |
2 |
Correct |
2 ms |
408 KB |
Output is correct |
3 |
Correct |
3 ms |
408 KB |
Output is correct |
4 |
Correct |
3 ms |
408 KB |
Output is correct |
5 |
Correct |
2 ms |
420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
496 KB |
Output is correct |
2 |
Correct |
2 ms |
496 KB |
Output is correct |
3 |
Correct |
2 ms |
496 KB |
Output is correct |
4 |
Correct |
3 ms |
544 KB |
Output is correct |
5 |
Correct |
3 ms |
544 KB |
Output is correct |
6 |
Correct |
2 ms |
544 KB |
Output is correct |
7 |
Correct |
2 ms |
544 KB |
Output is correct |
8 |
Correct |
3 ms |
544 KB |
Output is correct |
9 |
Correct |
2 ms |
544 KB |
Output is correct |
10 |
Correct |
2 ms |
544 KB |
Output is correct |
11 |
Correct |
2 ms |
552 KB |
Output is correct |
12 |
Correct |
2 ms |
552 KB |
Output is correct |
13 |
Correct |
3 ms |
572 KB |
Output is correct |
14 |
Correct |
3 ms |
572 KB |
Output is correct |
15 |
Correct |
3 ms |
572 KB |
Output is correct |
16 |
Correct |
3 ms |
572 KB |
Output is correct |
17 |
Correct |
2 ms |
748 KB |
Output is correct |
18 |
Correct |
2 ms |
748 KB |
Output is correct |
19 |
Correct |
2 ms |
748 KB |
Output is correct |
20 |
Correct |
2 ms |
748 KB |
Output is correct |
21 |
Correct |
2 ms |
748 KB |
Output is correct |
22 |
Correct |
3 ms |
748 KB |
Output is correct |
23 |
Correct |
2 ms |
748 KB |
Output is correct |
24 |
Correct |
2 ms |
748 KB |
Output is correct |
25 |
Correct |
2 ms |
748 KB |
Output is correct |
26 |
Correct |
3 ms |
748 KB |
Output is correct |
27 |
Correct |
2 ms |
756 KB |
Output is correct |
28 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
756 KB |
Output is correct |
2 |
Correct |
2 ms |
756 KB |
Output is correct |
3 |
Correct |
3 ms |
756 KB |
Output is correct |
4 |
Correct |
2 ms |
756 KB |
Output is correct |
5 |
Correct |
2 ms |
756 KB |
Output is correct |
6 |
Correct |
3 ms |
756 KB |
Output is correct |
7 |
Correct |
3 ms |
756 KB |
Output is correct |
8 |
Correct |
3 ms |
756 KB |
Output is correct |
9 |
Correct |
2 ms |
756 KB |
Output is correct |
10 |
Correct |
3 ms |
756 KB |
Output is correct |
11 |
Correct |
3 ms |
756 KB |
Output is correct |
12 |
Correct |
3 ms |
756 KB |
Output is correct |
13 |
Correct |
3 ms |
756 KB |
Output is correct |
14 |
Correct |
3 ms |
756 KB |
Output is correct |
15 |
Correct |
2 ms |
756 KB |
Output is correct |
16 |
Correct |
2 ms |
756 KB |
Output is correct |
17 |
Correct |
3 ms |
756 KB |
Output is correct |
18 |
Correct |
3 ms |
756 KB |
Output is correct |
19 |
Correct |
3 ms |
756 KB |
Output is correct |
20 |
Correct |
2 ms |
756 KB |
Output is correct |
21 |
Correct |
4 ms |
756 KB |
Output is correct |
22 |
Correct |
3 ms |
756 KB |
Output is correct |
23 |
Correct |
3 ms |
756 KB |
Output is correct |
24 |
Correct |
4 ms |
756 KB |
Output is correct |
25 |
Correct |
4 ms |
756 KB |
Output is correct |
26 |
Correct |
4 ms |
756 KB |
Output is correct |
27 |
Correct |
4 ms |
756 KB |
Output is correct |
28 |
Correct |
3 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |