#include "bits/stdc++.h"
#include "ricehub.h"
#define i64 long long
using namespace std;
const int sz = 2e5 + 10;
int a[sz];
int n;
i64 b;
bool che(int x) {
int ra = x / 2;
int ps = ra;
i64 sm = 0;
for (int i = 0; i < x; i ++) {
sm += abs(a[i] - a[ps]);
}
// cout << x << ' ' << ps << ' ' << sm << '\n';
if (sm <= b) {
return true;
}
ps ++;
for (; ps < n - ra + !(x % 2); ps ++) {
int pps = ps - 1; // previous ps
sm -= abs(a[pps - ra] - a[pps]); // delete leftmost
sm += abs(a[ps + ra - !(x % 2)] - a[ps]); // add rightmost
if (!(x % 2)) {
// cout << "[" << a[pps - ra] << "] [" << a[ps + ra] << "]\n";
sm += (ra) * abs(a[pps] - a[ps]);
sm -= (ra - 1) * abs(a[pps] - a[ps]);
}
// cout << x << ' ' << ps << ' ' << sm << '\n';
if (sm <= b) {
return true;
}
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
int le, ri;
le = 0, ri = R + 1;
for (int i = 0; i < R; i ++) {
a[i] = X[i];
}
b = B;
n = R;
while (1 < ri - le) {
int mi = le + (ri - le) / 2;
if (che(mi)) {
le = mi;
} else {
ri = mi;
}
}
return le;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
444 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
604 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
440 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
3 ms |
604 KB |
Output is correct |
3 |
Correct |
9 ms |
2140 KB |
Output is correct |
4 |
Correct |
9 ms |
2140 KB |
Output is correct |
5 |
Correct |
8 ms |
1084 KB |
Output is correct |
6 |
Correct |
5 ms |
1104 KB |
Output is correct |
7 |
Correct |
8 ms |
1856 KB |
Output is correct |
8 |
Correct |
14 ms |
1884 KB |
Output is correct |
9 |
Correct |
4 ms |
1116 KB |
Output is correct |
10 |
Correct |
4 ms |
1116 KB |
Output is correct |
11 |
Correct |
10 ms |
2140 KB |
Output is correct |
12 |
Correct |
10 ms |
2104 KB |
Output is correct |
13 |
Correct |
5 ms |
1116 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
13 ms |
1672 KB |
Output is correct |
16 |
Correct |
7 ms |
1628 KB |
Output is correct |
17 |
Correct |
12 ms |
1988 KB |
Output is correct |
18 |
Correct |
8 ms |
1880 KB |
Output is correct |
19 |
Correct |
10 ms |
2024 KB |
Output is correct |
20 |
Correct |
9 ms |
2136 KB |
Output is correct |