#include "bits/stdc++.h"
#include "ricehub.h"
#define i64 long long
using namespace std;
const i64 sz = 2e5 + 10;
i64 a[sz];
i64 n;
i64 b;
bool che(i64 x) {
i64 lra = x / 2;
i64 rra = lra - !(x % 2);
i64 ps = lra;
i64 sm = 0;
for (i64 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 - rra; ps ++) {
i64 pps = ps - 1; // previous ps
sm -= abs(a[pps - lra] - a[pps]); // delete leftmost
// if (0 < rra) { // if x is not 2
sm -= abs(a[pps] - a[ps]); // delete new ps
sm -= (rra - 1); // distance to right decreases
sm += abs(a[ps + rra] - a[ps]); // add rightmost
// }
sm += abs(a[pps] - a[ps]); // add previous ps
sm += (lra - 1); // distance to left increases
// cout << x << ' ' << ps << ' ' << sm << '\n';
if (sm <= b) {
return true;
}
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
i64 le, ri;
le = 0, ri = R + 1;
for (i64 i = 0; i < R; i ++) {
a[i] = X[i];
}
b = B;
n = R;
while (1 < ri - le) {
i64 mi = le + (ri - le) / 2;
if (che(mi)) {
le = mi;
} else {
ri = mi;
}
}
return le;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
708 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |