#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
using ll = long long;
#define MAXN (1000005)
int besthub(int R, int L, int X[], long long B){
ll l = 0;
ll r = 0;
ll sum = 0;
ll cur = 0;
ll budget = 0;
for(ll i = 1;i < R;i++){
budget += abs(X[i] - X[0]);
if(budget > B){
break;
}
cur++;
R++;
}
sum = max(sum,cur);
for(ll i = 1;i < R;i++){
budget += abs(i - l) * abs(X[i] - X[i - 1]);
budget -= abs(r - i + 1) * abs(X[i] - X[i - 1]);
while(budget > B && l < i){
budget -= abs(X[i] - X[l]);
l++;
}
while(r < R - 1 && budget + X[r + 1] <= B){
r++;
budget += X[r];
cur++;
}
while(l < i && r < R - 1){
if(X[l] >= X[r + 1]){
budget -= abs(X[i] - X[l]);
budget += abs(X[r + 1] - X[i]);
l++;
r++;
}
}
while(r < R - 1 && budget + X[r + 1] <= B){
r++;
budget += X[r];
cur++;
}
if(budget <= B){
sum = max(sum,cur);
}
}
return sum;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 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 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |