#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
long long pf[maxn], ki, ka, mid, idxtengah, cost, res, ans;
int besthub(int R, int L, int X[], long long B)
{
for(int i=0; i<R; i++) {
pf[i]=X[i]+(i?pf[i-1]:0);
ki=0, ka=i;
while(ki<=ka) {
mid=(ki+ka)/2, idxtengah=(mid+i)/2;
cost=(idxtengah-mid)*X[idxtengah]-((idxtengah?pf[idxtengah-1]:0)-(mid?pf[mid-1]:0));
cost+=pf[i]-pf[idxtengah]-((i-idxtengah)*X[idxtengah]);
if(cost<=B) res=mid, ka=mid-1;
else ki=mid+1;
}
ans=max(ans, i-res+1);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
304 KB |
Output is correct |
21 |
Correct |
0 ms |
308 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
308 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
304 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
308 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
352 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
596 KB |
Output is correct |
3 |
Correct |
17 ms |
2488 KB |
Output is correct |
4 |
Correct |
15 ms |
2516 KB |
Output is correct |
5 |
Correct |
7 ms |
1236 KB |
Output is correct |
6 |
Correct |
7 ms |
1236 KB |
Output is correct |
7 |
Correct |
18 ms |
2188 KB |
Output is correct |
8 |
Correct |
13 ms |
2132 KB |
Output is correct |
9 |
Correct |
8 ms |
1108 KB |
Output is correct |
10 |
Correct |
7 ms |
1096 KB |
Output is correct |
11 |
Correct |
16 ms |
2428 KB |
Output is correct |
12 |
Correct |
15 ms |
2496 KB |
Output is correct |
13 |
Correct |
8 ms |
1252 KB |
Output is correct |
14 |
Correct |
7 ms |
1252 KB |
Output is correct |
15 |
Correct |
12 ms |
1976 KB |
Output is correct |
16 |
Correct |
12 ms |
1876 KB |
Output is correct |
17 |
Correct |
13 ms |
2228 KB |
Output is correct |
18 |
Correct |
13 ms |
2180 KB |
Output is correct |
19 |
Correct |
14 ms |
2320 KB |
Output is correct |
20 |
Correct |
15 ms |
2316 KB |
Output is correct |