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 "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
using pi = pair<int,int>;
int qs[100005]={};
int ans=0;
int besthub(int R, int L, int X[], long long B)
{
for(int i=1;i<=R;i++){
qs[i]=qs[i-1]+X[i-1];
}
int l=1,r=R;
long long cost;
while(l<=r){
int len=(r+l)>>1;
bool v =false;
//iterate start points
//S=i,E=i+len-1,N=(s+e)/2
int S,E,N;
//cout << len << '=';
for(int i=1;i<=(R-len+1);i++){
S=i,E=i+len-1,N=(S+E+1)/2;
cost = (X[N-1]*(N-1-S)) - qs[N-1] + qs[S-1] + qs[E] - qs[N] - ((E-N-1)*X[N-1]);
//cout << cost << ' ';
if(cost<=B){
v=true;
break;
}
}
//cout << endl;
if(v){
ans=max(len,ans);
l=len+1;
}else{
r=len-1;
}
}
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... |