#include<bits/stdc++.h>
#include "ricehub.h"
using namespace std;
const int lim = 1e5+5;
typedef long long ll;
int x[lim], sv[lim], ans;
ll bucket;
bool valid(int l, int r){
int mid = (l+r)/2;
ll cost = sv[r]-sv[mid] - (r-mid)*x[mid] + (mid-l)*x[mid] - (sv[mid-1]-sv[l-1]);
return cost <= bucket;
}
int besthub(int R, int L, int X[], long long B){
bucket = B;
for(int i = 1; i <= R; i++){
x[i] = X[i-1];
sv[i] = sv[i-1] + x[i];
}
int r = 1;
for(int l = 1; l <= R; l++){
while(r <= R && valid(l, r)){
ans = max(r-l+1, ans);
r++;
}
}
return ans;
}
# | 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... |