#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];
ll s = -(preS[m + 1] - preS[i] - 1ll * (m - i + 1) * placement) +
(preS[mid + 1] - preS[m] - 1ll * (mid - m + 1) * placement);
if(s <= B){
ans = max(ans, (mid - i + 1));
l = mid + 1;
}
else{
r = mid - 1;
}
}
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
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 |
0 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 |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 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 |
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
2 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 |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
468 KB |
Output is correct |
2 |
Correct |
3 ms |
536 KB |
Output is correct |
3 |
Correct |
17 ms |
1364 KB |
Output is correct |
4 |
Correct |
17 ms |
1376 KB |
Output is correct |
5 |
Correct |
7 ms |
852 KB |
Output is correct |
6 |
Correct |
7 ms |
852 KB |
Output is correct |
7 |
Correct |
16 ms |
1364 KB |
Output is correct |
8 |
Correct |
15 ms |
1488 KB |
Output is correct |
9 |
Correct |
9 ms |
896 KB |
Output is correct |
10 |
Correct |
9 ms |
852 KB |
Output is correct |
11 |
Correct |
18 ms |
1464 KB |
Output is correct |
12 |
Correct |
16 ms |
1392 KB |
Output is correct |
13 |
Correct |
7 ms |
852 KB |
Output is correct |
14 |
Correct |
8 ms |
852 KB |
Output is correct |
15 |
Correct |
13 ms |
1080 KB |
Output is correct |
16 |
Correct |
12 ms |
1108 KB |
Output is correct |
17 |
Correct |
15 ms |
1236 KB |
Output is correct |
18 |
Correct |
15 ms |
1312 KB |
Output is correct |
19 |
Correct |
16 ms |
1364 KB |
Output is correct |
20 |
Correct |
17 ms |
1384 KB |
Output is correct |