#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
long long b;
int l, r, *x;
long long prefix[N];
long long calc_sum(int from, int to){
if(from == 0){
return prefix[to];
}
return prefix[to] - prefix[from - 1];
}
long long find_score(int from, int to){
long long mid;
if((to - from) & 1){
mid = (x[(to + from) / 2] + x[(to + from) / 2 + 1]) / 2;
}
else{
mid = x[(to + from) / 2];
}
long long ans = ((to + from) / 2ll - from + 1ll) * mid - calc_sum(from, (to + from) / 2);
ans += calc_sum((to + from) / 2 + 1, to) - (to - (to + from) / 2ll) * mid;
return ans;
}
int besthub(int _r, int _l, int *_x, long long _b){
r = _r;
l = _l;
x = _x;
b = _b;
int ans = 0;
prefix[0] = x[0];
for(int i = 1; i < r; i++){
prefix[i] = x[i] + prefix[i - 1];
}
for(int i = 0; i < r; i++){
int j;
for(j = i; j < r && find_score(i, j) <= b; j++);
j--;
ans = max(ans, j - i + 1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
252 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
376 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
3 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
3 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
6 ms |
380 KB |
Output is correct |
14 |
Correct |
6 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
4 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
5 ms |
376 KB |
Output is correct |
21 |
Correct |
10 ms |
376 KB |
Output is correct |
22 |
Correct |
10 ms |
376 KB |
Output is correct |
23 |
Correct |
80 ms |
380 KB |
Output is correct |
24 |
Correct |
80 ms |
500 KB |
Output is correct |
25 |
Correct |
80 ms |
376 KB |
Output is correct |
26 |
Correct |
80 ms |
504 KB |
Output is correct |
27 |
Correct |
61 ms |
508 KB |
Output is correct |
28 |
Correct |
62 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
632 KB |
Output is correct |
2 |
Correct |
15 ms |
760 KB |
Output is correct |
3 |
Execution timed out |
1065 ms |
2552 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |