#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(int dis, int n, vector < ll > &pre, vector < ll > &x, ll B) {
ll ans = 1e16;
for (int l = 1; l + dis - 1 <= n; l++) {
int r = l + dis - 1;
int med = (l + r) >> 1; // x[l] -> x[r] => x[l] -> x[med] and x[med] -> x[r]
ll mb = x[med] * (med - l + 1) - (pre[med] - pre[l - 1]) + (pre[r] - pre[med - 1]) - x[med] * (r - med + 1);
ans = min(ans, mb);
}
return ans <= B;
}
int besthub(int R, int L, int X[], ll B) {
int n = R;
vector < ll > pre(n + 1), x(n + 1);
pre[0] = 0;
for (int i = 1; i <= n; i++) {
x[i] = 1LL * X[i - 1];
pre[i] = pre[i - 1] + x[i];
}
int l = 1, r = n;
while(r - l > 1) {
int mid = (l + r) >> 1;
if (check(mid, n, pre, x, B))
l = mid;
else
r = mid - 1;
}
if (check(r, n, pre, x, B))
return r;
else if (check(l, n, pre, x, B))
return l;
else
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
304 KB |
Output is correct |
9 |
Correct |
0 ms |
308 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 |
0 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 |
1 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 |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
0 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 |
308 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
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 |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
308 KB |
Output is correct |
6 |
Correct |
0 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
332 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 |
260 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
312 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
716 KB |
Output is correct |
2 |
Correct |
3 ms |
836 KB |
Output is correct |
3 |
Correct |
13 ms |
3280 KB |
Output is correct |
4 |
Correct |
19 ms |
3268 KB |
Output is correct |
5 |
Correct |
7 ms |
1560 KB |
Output is correct |
6 |
Correct |
8 ms |
1612 KB |
Output is correct |
7 |
Correct |
14 ms |
2960 KB |
Output is correct |
8 |
Correct |
11 ms |
3020 KB |
Output is correct |
9 |
Correct |
6 ms |
1484 KB |
Output is correct |
10 |
Correct |
6 ms |
1484 KB |
Output is correct |
11 |
Correct |
12 ms |
3256 KB |
Output is correct |
12 |
Correct |
13 ms |
3272 KB |
Output is correct |
13 |
Correct |
7 ms |
1616 KB |
Output is correct |
14 |
Correct |
8 ms |
1612 KB |
Output is correct |
15 |
Correct |
9 ms |
2632 KB |
Output is correct |
16 |
Correct |
10 ms |
2616 KB |
Output is correct |
17 |
Correct |
11 ms |
3012 KB |
Output is correct |
18 |
Correct |
11 ms |
2912 KB |
Output is correct |
19 |
Correct |
12 ms |
3140 KB |
Output is correct |
20 |
Correct |
18 ms |
3124 KB |
Output is correct |