#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B) {
int ans = 0;
vector<long long> pref(R, 0);
for (int i = 0; i < R; i++) {
pref[i] = i == 0 ? X[0] : (pref[i - 1] + X[i]);
}
for (int i = 0; i < R; i++) {
int l = 1, r = R;
while (l <= r) {
int m = (l + r) >> 1;
int left = i - m / 2 + 1;
int right = i + (m + 1) / 2;
bool good = false;
if (left >= 0 && right < R) {
long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i];
long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]);
good |= d1 + d2 <= B;
}
left--;
right--;
if (left >= 0 && right < R) {
long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i];
long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]);
good |= d1 + d2 <= B;
}
left+=2;
right+=2;
if (left >= 0 && right < R) {
long long d1 = pref[right] - pref[i] - (right - i) * 1ll * X[i];
long long d2 = 1ll * X[i] * (i - left + 1) - pref[i] + (left == 0 ? 0 : pref[left - 1]);
good |= d1 + d2 <= B;
}
if (good) {
l = m + 1;
ans = max(ans, m);
} else r = m - 1;
}
}
return ans;
}
# |
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 |
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 |
0 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 |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 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 |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 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 |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
2 ms |
332 KB |
Output is correct |
22 |
Correct |
2 ms |
332 KB |
Output is correct |
23 |
Correct |
2 ms |
332 KB |
Output is correct |
24 |
Correct |
2 ms |
332 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
2 ms |
332 KB |
Output is correct |
27 |
Correct |
2 ms |
332 KB |
Output is correct |
28 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
460 KB |
Output is correct |
2 |
Correct |
6 ms |
460 KB |
Output is correct |
3 |
Correct |
30 ms |
1488 KB |
Output is correct |
4 |
Correct |
30 ms |
1364 KB |
Output is correct |
5 |
Correct |
14 ms |
844 KB |
Output is correct |
6 |
Correct |
15 ms |
844 KB |
Output is correct |
7 |
Correct |
29 ms |
1484 KB |
Output is correct |
8 |
Correct |
28 ms |
1368 KB |
Output is correct |
9 |
Correct |
15 ms |
844 KB |
Output is correct |
10 |
Correct |
14 ms |
844 KB |
Output is correct |
11 |
Correct |
30 ms |
1400 KB |
Output is correct |
12 |
Correct |
30 ms |
1484 KB |
Output is correct |
13 |
Correct |
15 ms |
844 KB |
Output is correct |
14 |
Correct |
15 ms |
844 KB |
Output is correct |
15 |
Correct |
22 ms |
1100 KB |
Output is correct |
16 |
Correct |
22 ms |
1100 KB |
Output is correct |
17 |
Correct |
26 ms |
1356 KB |
Output is correct |
18 |
Correct |
26 ms |
1360 KB |
Output is correct |
19 |
Correct |
29 ms |
1356 KB |
Output is correct |
20 |
Correct |
28 ms |
1356 KB |
Output is correct |