#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nax = 1e5 + 5;
ll n, maxi, a[nax], pref[nax], suff[nax];
ll b;
bool chk(int x) {
if (x > n) return false;
if (x <= 1) return true;
for (int i = 1; i <= n - x + 1; ++i) {
int l = i, r = i + x - 1;
int median = l + (r - l) / 2;
ll num_left = max(0LL, (median - 1 - l) + 1LL);
ll num_right = max(0LL, r - (median + 1) + 1LL);
ll cost_left = 1LL * a[median] * num_left - (1LL * pref[median - 1] - pref[l - 1]);
ll cost_right = 1LL * suff[median + 1] - suff[r + 1] - 1LL * a[median] * num_right;
if (cost_left + cost_right <= b) return true;
}
return false;
}
int solve() {
for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] + a[i];
int l = 1, r = n;
while (r >= l) {
int mid = (l + r) / 2;
bool status = chk(mid);
if (status) {
if (chk(mid + 1)) l = mid + 1;
else {
return mid;
}
}
else {
r = mid - 1;
}
}
return 1;
}
int besthub(int R, int L, int X[], long long B) {
n = R;
maxi = L;
for (int i = 0; i < R; ++i) a[i + 1] = X[i];
b = B;
return solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
288 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
416 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
640 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
896 KB |
Output is correct |
2 |
Correct |
4 ms |
896 KB |
Output is correct |
3 |
Correct |
18 ms |
3072 KB |
Output is correct |
4 |
Correct |
18 ms |
3200 KB |
Output is correct |
5 |
Correct |
9 ms |
2048 KB |
Output is correct |
6 |
Correct |
11 ms |
2176 KB |
Output is correct |
7 |
Correct |
15 ms |
3840 KB |
Output is correct |
8 |
Correct |
15 ms |
3840 KB |
Output is correct |
9 |
Correct |
9 ms |
2176 KB |
Output is correct |
10 |
Correct |
9 ms |
2048 KB |
Output is correct |
11 |
Correct |
19 ms |
4096 KB |
Output is correct |
12 |
Correct |
19 ms |
4096 KB |
Output is correct |
13 |
Correct |
10 ms |
2048 KB |
Output is correct |
14 |
Correct |
10 ms |
2048 KB |
Output is correct |
15 |
Correct |
14 ms |
3200 KB |
Output is correct |
16 |
Correct |
15 ms |
3200 KB |
Output is correct |
17 |
Correct |
17 ms |
3712 KB |
Output is correct |
18 |
Correct |
17 ms |
3840 KB |
Output is correct |
19 |
Correct |
18 ms |
3968 KB |
Output is correct |
20 |
Correct |
18 ms |
3968 KB |
Output is correct |