#include "ricehub.h"
#include <bits/stdc++.h>
#define num long long
#define inf 1e18
using namespace std;
vector<int> X;
int _besthub (int R, int L, num B) {
int mxCount = 0;
int left = 0;
int right = 0;
num cost = 0;
for (int idx = 0; idx < R; idx ++) {
while (cost > B) {
if (left == right) {
left = idx;
right = idx;
cost = 0;
break;
}
num dlc = X[left ] - X[idx];
num drc = X[right] - X[idx];
cost -= max(dlc, drc);
if (dlc >= drc) left ++;
else right --;
}
while (right != R - 1) {
if (X[right + 1] - X[idx] + cost <= B) {
cost += X[right + 1] - X[idx];
right ++;
} else if (X[right + 1] - X[idx]
- (X[idx] - X[left])
+ cost <= B) {
right ++;
left ++;
cost += X[right + 1] - X[idx] - (X[idx] - X[left]);
} else break ;
}
if (idx + 1 != R) {
num delta = X[idx + 1] - X[idx];
cost += delta * (idx - left + 1);
cost -= delta * (right - idx);
}
mxCount = max(mxCount, right - left + 1);
}
return mxCount;
}
int besthub(int R, int L, int _X[], num B)
{
X.resize(R);
for (int i = 0; i < R; i ++)
X[i] = _X[i];
return _besthub(R, L, B);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |