This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |