#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int x[], ll B) {
vector<ll> X(R + 1);
X[0] = -(ll)1e18;
for (int i = 1; i <= R; i++) X[i] = x[i - 1];
int l = 1, r = R;
ll pf[R + 1];
pf[0] = 0;
for (int i = 1; i <= R; i++) pf[i] = pf[i - 1] + X[i];
auto check = [&](int mid) {
for (int l = 1; l + mid <= R + 1; l++) {
int r = l + mid - 1;
int median = (r + l) / 2;
for (int it = max(l, median - 5); it <= min(r, median + 5); it++) {
ll sum = 0;
if (it != l) sum += (it - l) * X[it] - (pf[it - 1] - pf[l - 1]);
if (it != r) sum += -(r - it) * X[it] + (pf[r] - pf[it]);
if (sum <= B) return true;
}
}
return false;
};
while (l <= r) {
int mid = (l + r) / 2;
if (check(mid)) l = mid + 1;
else r = mid - 1;
}
return l - 1;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
308 KB |
Output is correct |
6 |
Correct |
0 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 |
312 KB |
Output is correct |
10 |
Correct |
0 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 |
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 |
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 |
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 |
0 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 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 |
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 |
316 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 |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
312 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
2 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
320 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 |
7 ms |
824 KB |
Output is correct |
2 |
Correct |
6 ms |
836 KB |
Output is correct |
3 |
Correct |
12 ms |
2924 KB |
Output is correct |
4 |
Correct |
11 ms |
2780 KB |
Output is correct |
5 |
Correct |
15 ms |
1604 KB |
Output is correct |
6 |
Correct |
15 ms |
1620 KB |
Output is correct |
7 |
Correct |
9 ms |
2872 KB |
Output is correct |
8 |
Correct |
9 ms |
2900 KB |
Output is correct |
9 |
Correct |
13 ms |
1492 KB |
Output is correct |
10 |
Correct |
14 ms |
1476 KB |
Output is correct |
11 |
Correct |
11 ms |
2828 KB |
Output is correct |
12 |
Correct |
11 ms |
2840 KB |
Output is correct |
13 |
Correct |
16 ms |
1608 KB |
Output is correct |
14 |
Correct |
16 ms |
1628 KB |
Output is correct |
15 |
Correct |
8 ms |
2388 KB |
Output is correct |
16 |
Correct |
8 ms |
2388 KB |
Output is correct |
17 |
Correct |
9 ms |
2976 KB |
Output is correct |
18 |
Correct |
9 ms |
2900 KB |
Output is correct |
19 |
Correct |
13 ms |
3156 KB |
Output is correct |
20 |
Correct |
10 ms |
3156 KB |
Output is correct |