#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
ll preS[R + 1] = {0};
for (int i = 1; i <= R; i++)
{
preS[i] = preS[i - 1] + X[i - 1];
}
int ans = 0;
for (int i = 0; i < R; i++)
{
int l = i, r = R - 1;
while(l <= r){
int mid = (l + r) / 2;
int m = (i + mid) / 2;
int placement = X[m];
int left = upper_bound(X, X + R, placement) - X - 1;
ll s = -(preS[left + 1] - preS[i] - 1ll * (left - i + 1) * placement) +
(preS[mid + 1] - preS[left] - 1ll * (mid - left + 1) * placement);
if(s <= B){
ans = max(ans, (mid - i + 1));
l = mid + 1;
}
else{
r = mid - 1;
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 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 |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
316 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
316 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 |
308 KB |
Output is correct |
11 |
Correct |
1 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 |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
316 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
2 ms |
324 KB |
Output is correct |
22 |
Correct |
2 ms |
340 KB |
Output is correct |
23 |
Correct |
4 ms |
340 KB |
Output is correct |
24 |
Correct |
4 ms |
320 KB |
Output is correct |
25 |
Correct |
4 ms |
340 KB |
Output is correct |
26 |
Correct |
4 ms |
340 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
4 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
580 KB |
Output is correct |
2 |
Correct |
16 ms |
668 KB |
Output is correct |
3 |
Correct |
94 ms |
2500 KB |
Output is correct |
4 |
Correct |
93 ms |
2540 KB |
Output is correct |
5 |
Correct |
22 ms |
1236 KB |
Output is correct |
6 |
Correct |
23 ms |
1108 KB |
Output is correct |
7 |
Correct |
51 ms |
2240 KB |
Output is correct |
8 |
Correct |
50 ms |
2236 KB |
Output is correct |
9 |
Correct |
35 ms |
1160 KB |
Output is correct |
10 |
Correct |
34 ms |
1108 KB |
Output is correct |
11 |
Correct |
93 ms |
2524 KB |
Output is correct |
12 |
Correct |
94 ms |
2520 KB |
Output is correct |
13 |
Correct |
45 ms |
1236 KB |
Output is correct |
14 |
Correct |
44 ms |
1272 KB |
Output is correct |
15 |
Correct |
69 ms |
1876 KB |
Output is correct |
16 |
Correct |
68 ms |
1940 KB |
Output is correct |
17 |
Correct |
84 ms |
2288 KB |
Output is correct |
18 |
Correct |
83 ms |
2288 KB |
Output is correct |
19 |
Correct |
88 ms |
2380 KB |
Output is correct |
20 |
Correct |
89 ms |
2388 KB |
Output is correct |