#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5;
long long sum[N];
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 = 1, 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 = 0;
if(mid == 2) ret = min(ret, sum[i + 1] - 2 * sum[i] + sum[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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
3 ms |
492 KB |
Output is correct |
5 |
Correct |
3 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
520 KB |
Output is correct |
3 |
Correct |
2 ms |
520 KB |
Output is correct |
4 |
Correct |
2 ms |
520 KB |
Output is correct |
5 |
Correct |
2 ms |
704 KB |
Output is correct |
6 |
Correct |
2 ms |
704 KB |
Output is correct |
7 |
Correct |
3 ms |
704 KB |
Output is correct |
8 |
Correct |
3 ms |
704 KB |
Output is correct |
9 |
Correct |
3 ms |
704 KB |
Output is correct |
10 |
Correct |
2 ms |
704 KB |
Output is correct |
11 |
Correct |
3 ms |
704 KB |
Output is correct |
12 |
Correct |
4 ms |
704 KB |
Output is correct |
13 |
Correct |
3 ms |
704 KB |
Output is correct |
14 |
Correct |
3 ms |
704 KB |
Output is correct |
15 |
Correct |
2 ms |
704 KB |
Output is correct |
16 |
Correct |
2 ms |
704 KB |
Output is correct |
17 |
Correct |
3 ms |
704 KB |
Output is correct |
18 |
Correct |
2 ms |
704 KB |
Output is correct |
19 |
Correct |
2 ms |
704 KB |
Output is correct |
20 |
Correct |
3 ms |
704 KB |
Output is correct |
21 |
Correct |
2 ms |
704 KB |
Output is correct |
22 |
Correct |
3 ms |
704 KB |
Output is correct |
23 |
Correct |
2 ms |
832 KB |
Output is correct |
24 |
Correct |
2 ms |
832 KB |
Output is correct |
25 |
Correct |
3 ms |
832 KB |
Output is correct |
26 |
Correct |
2 ms |
832 KB |
Output is correct |
27 |
Correct |
4 ms |
832 KB |
Output is correct |
28 |
Correct |
3 ms |
832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
832 KB |
Output is correct |
2 |
Correct |
3 ms |
832 KB |
Output is correct |
3 |
Correct |
2 ms |
832 KB |
Output is correct |
4 |
Correct |
3 ms |
836 KB |
Output is correct |
5 |
Correct |
3 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
864 KB |
Output is correct |
7 |
Correct |
2 ms |
868 KB |
Output is correct |
8 |
Correct |
2 ms |
892 KB |
Output is correct |
9 |
Correct |
3 ms |
900 KB |
Output is correct |
10 |
Correct |
3 ms |
904 KB |
Output is correct |
11 |
Correct |
3 ms |
1036 KB |
Output is correct |
12 |
Correct |
3 ms |
1036 KB |
Output is correct |
13 |
Correct |
2 ms |
1036 KB |
Output is correct |
14 |
Correct |
2 ms |
1036 KB |
Output is correct |
15 |
Correct |
2 ms |
1036 KB |
Output is correct |
16 |
Correct |
3 ms |
1036 KB |
Output is correct |
17 |
Correct |
3 ms |
1104 KB |
Output is correct |
18 |
Correct |
3 ms |
1104 KB |
Output is correct |
19 |
Correct |
3 ms |
1104 KB |
Output is correct |
20 |
Correct |
3 ms |
1104 KB |
Output is correct |
21 |
Correct |
4 ms |
1104 KB |
Output is correct |
22 |
Correct |
4 ms |
1120 KB |
Output is correct |
23 |
Correct |
4 ms |
1120 KB |
Output is correct |
24 |
Correct |
4 ms |
1168 KB |
Output is correct |
25 |
Correct |
4 ms |
1240 KB |
Output is correct |
26 |
Correct |
4 ms |
1240 KB |
Output is correct |
27 |
Correct |
4 ms |
1268 KB |
Output is correct |
28 |
Correct |
7 ms |
1296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
1468 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |