#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
long long int pos[100002];
long long int acumulado[100002];
long long int cal(int l, int r, int m){
long long int suma = 0;
if(r > m){
suma+= (acumulado[r] - acumulado[m]) - ((r - m) * pos[m]);
}
if(l < m){
suma+= ((m - l) * pos[m]) - (acumulado[m - 1] - acumulado[l - 1]);
}
return suma;
}
int besthub(int R, int L, int X[], long long B)
{
for(int i = 0; i < R; ++i){
pos[i + 1] = X[i];
acumulado[i + 1] = acumulado[i] + pos[i + 1];
}
int l = 1, r = 1, m = 1, ans = 1, n = R;
while(l < n || r < n){
m = (l + r) / 2;
if(cal(l, r, m) <= B){
ans = max(ans, r - l + 1);
if(r < n){
r++;
}else{
l++;
}
}else{
l++;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
304 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
0 ms |
204 KB |
Output is correct |
26 |
Correct |
0 ms |
204 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
716 KB |
Output is correct |
2 |
Correct |
2 ms |
716 KB |
Output is correct |
3 |
Correct |
16 ms |
3276 KB |
Output is correct |
4 |
Correct |
12 ms |
3200 KB |
Output is correct |
5 |
Correct |
6 ms |
1612 KB |
Output is correct |
6 |
Correct |
5 ms |
1612 KB |
Output is correct |
7 |
Correct |
11 ms |
3020 KB |
Output is correct |
8 |
Correct |
11 ms |
2932 KB |
Output is correct |
9 |
Correct |
5 ms |
1576 KB |
Output is correct |
10 |
Correct |
5 ms |
1484 KB |
Output is correct |
11 |
Correct |
12 ms |
3240 KB |
Output is correct |
12 |
Correct |
12 ms |
3200 KB |
Output is correct |
13 |
Correct |
5 ms |
1676 KB |
Output is correct |
14 |
Correct |
6 ms |
1612 KB |
Output is correct |
15 |
Correct |
13 ms |
2508 KB |
Output is correct |
16 |
Correct |
11 ms |
2508 KB |
Output is correct |
17 |
Correct |
12 ms |
2876 KB |
Output is correct |
18 |
Correct |
12 ms |
2956 KB |
Output is correct |
19 |
Correct |
13 ms |
3084 KB |
Output is correct |
20 |
Correct |
13 ms |
3128 KB |
Output is correct |