#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll besthub(int n, int L, int pos[], ll bud){
ll l,p,sm;
l=p=sm=0;
while(p<n-1 && sm+pos[p+1]-pos[0]<=bud){
p++;
sm+=pos[p]-pos[0];
}
ll mx=p+1;
for (ll i = 1; i<n; i++){
sm+=(pos[i]-pos[i-1])*(i-l);
sm-=(pos[i]-pos[i-1])*(p-i+1);
while(sm>bud && l<i){
sm-=pos[i]-pos[l];
l++;
}
while(p<n-1 && sm+pos[p+1]-pos[i]<=bud){
p++;
sm+=pos[p]-pos[i];
}
while(l<i && p<n-1 && (pos[p+1]-pos[i])<(pos[i]-pos[l])){
sm-=pos[i]-pos[l];
l++;
while(p<n-1 && sm+pos[p+1]-pos[i]<=bud){
p++;
sm+=pos[p]-pos[i];
}
}
mx=max(mx,p-l+1);
}
return mx;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
600 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
532 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
604 KB |
Output is correct |
3 |
Correct |
10 ms |
3676 KB |
Output is correct |
4 |
Correct |
10 ms |
3676 KB |
Output is correct |
5 |
Correct |
5 ms |
2908 KB |
Output is correct |
6 |
Correct |
5 ms |
2984 KB |
Output is correct |
7 |
Correct |
9 ms |
3420 KB |
Output is correct |
8 |
Correct |
9 ms |
3420 KB |
Output is correct |
9 |
Correct |
4 ms |
2908 KB |
Output is correct |
10 |
Correct |
4 ms |
2908 KB |
Output is correct |
11 |
Correct |
11 ms |
3932 KB |
Output is correct |
12 |
Correct |
10 ms |
3672 KB |
Output is correct |
13 |
Correct |
7 ms |
2908 KB |
Output is correct |
14 |
Correct |
5 ms |
2924 KB |
Output is correct |
15 |
Correct |
7 ms |
3420 KB |
Output is correct |
16 |
Correct |
8 ms |
3432 KB |
Output is correct |
17 |
Correct |
9 ms |
3680 KB |
Output is correct |
18 |
Correct |
9 ms |
3420 KB |
Output is correct |
19 |
Correct |
9 ms |
3676 KB |
Output is correct |
20 |
Correct |
10 ms |
3552 KB |
Output is correct |