#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B) {
auto cost = [&](int x, int y) { return abs(X[x] - X[y]); };
int ans = 1;
int pb = B;
int l, r;
l = r = 0;
for (; l + 1 < R;) {
while (r + 1 < R) {
int lm = (l + r) / 2;
int cm = (l + r + 1) / 2;
int cb = pb;
if (lm != cm) {
cb += (lm - l + 1) * cost(cm, lm);
cb -= (r - cm + 1) * cost(cm, lm);
}
cb += cost(cm, r);
if (cb > B)
break;
pb = cb;
r++;
}
ans = max(ans, r - l + 1);
// l++;
int lm = (l + r) / 2;
int cm = (l + r + 1) / 2;
if (lm != cm) {
pb += (lm - l + 1) * cost(cm, lm);
pb -= (r - cm + 1) * cost(cm, lm);
}
pb -= cost(cm, l);
l++;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |