#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 + sum[i + m]);
}
}
if(ret <= B) res = mid, l = mid + 1;
else r = mid - 1;
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
488 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
3 ms |
488 KB |
Output is correct |
4 |
Incorrect |
2 ms |
524 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
572 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |