#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<typename T> bool ckmx(T& a, const T& b){if(a < b) return a = b, true; return false;}
const int N = 1e5+5;
ll n, budget;
ll pref[N];
ll calc(int l, int r){
int mid = (l+r)>>1;
ll valMid = pref[mid] - pref[mid-1];
ll prefixLmid = valMid * (1ll * (mid - l+1)) - (pref[mid] - pref[l-1]);
ll prefixmidR = (pref[r] - pref[mid]) - valMid * (1ll * (r - mid));
return prefixLmid + prefixmidR;
}
bool ok(int l, int r){
return calc(l, r) <= budget;
}
int besthub(int R, int L, int x[], ll B)
{
n = R, budget = B;
for(int i = 1; i <= n; i++){
pref[i] = pref[i-1] + 1ll * x[i-1];
}
int pointer = 1, answer = 0;
for(int i = 1; i <= n; i++){
while(pointer <= n && ok(i, pointer)) pointer++;
ckmx(answer, pointer - i);
}
return answer;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
352 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
356 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
352 KB |
Output is correct |
3 |
Correct |
0 ms |
352 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
448 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
448 KB |
Output is correct |
5 |
Correct |
0 ms |
352 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
352 KB |
Output is correct |
11 |
Correct |
0 ms |
352 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
0 ms |
356 KB |
Output is correct |
14 |
Correct |
1 ms |
352 KB |
Output is correct |
15 |
Correct |
0 ms |
356 KB |
Output is correct |
16 |
Correct |
0 ms |
352 KB |
Output is correct |
17 |
Correct |
0 ms |
352 KB |
Output is correct |
18 |
Correct |
0 ms |
352 KB |
Output is correct |
19 |
Correct |
1 ms |
352 KB |
Output is correct |
20 |
Correct |
0 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
352 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
496 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
9 ms |
2608 KB |
Output is correct |
4 |
Correct |
9 ms |
2652 KB |
Output is correct |
5 |
Correct |
4 ms |
1132 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
8 ms |
2396 KB |
Output is correct |
8 |
Correct |
8 ms |
2168 KB |
Output is correct |
9 |
Correct |
4 ms |
1116 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
11 |
Correct |
9 ms |
2524 KB |
Output is correct |
12 |
Correct |
9 ms |
2648 KB |
Output is correct |
13 |
Correct |
5 ms |
1248 KB |
Output is correct |
14 |
Correct |
5 ms |
1372 KB |
Output is correct |
15 |
Correct |
7 ms |
2108 KB |
Output is correct |
16 |
Correct |
7 ms |
1996 KB |
Output is correct |
17 |
Correct |
9 ms |
2396 KB |
Output is correct |
18 |
Correct |
8 ms |
2244 KB |
Output is correct |
19 |
Correct |
9 ms |
2500 KB |
Output is correct |
20 |
Correct |
9 ms |
2572 KB |
Output is correct |