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>
using namespace std;
long long const inf=1e16;
int const N=1e5+5;
long long pre[N];
int cor[N];
long long bug=0;
bool cost(int l,int r){
// cout<<l<<' '<<r<<" checking for it"<<endl;
int p=(l+r)/2;
// cout<<p<<" hub"<<endl;
long long c=0;
int s1=p-l;
int s2=(r+1)-p;
long long sm1=(cor[p]*s1)-(pre[p]-pre[l]);
long long sm2=(pre[r+1]-pre[p])-(cor[p]*s2);
c=sm1+sm2;
// cout<<c<<endl;
return (c<=bug);
}
int besthub(int R, int L, int X[], long long B){
bug=B;
for (int i = 0; i < R; ++i){
pre[i+1]=pre[i]+X[i];
cor[i]=X[i];
}
int low=1,high=R+1;
while(high-low>1){
int mid=(high+low)/2;
// cout<<mid<<' '<<" mid"<<endl;
bool b=0;
for (int i = 0; (i+mid)-1 < R; ++i)
b|=cost(i,(i+mid)-1);
if(b)
low=mid;
else
high=mid;
}
return low;
}
# | 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... |