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;
#define ll long long
const int MAXN = 1e5+7;
ll t[MAXN], prefix[MAXN];
ll ra,rb,sa,sb,j,m,s;
bool f(int x, long long B,int R){
for(int i=0;i<=R-x;i++){
j=i+x-1;
m=(i+j)/2;
if(i) sb=prefix[m-1]-prefix[i-1];
else sb=prefix[m-1];
sa=prefix[j]-prefix[m];
rb=t[m]*(m-i)-sb;
ra=sa-t[m]*(j-m);
if(ra+rb<=B) return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B){
int p=0,k=R;
prefix[0]=X[0];
t[0]=X[0];
for(int i=1;i<R;i++){
t[i]=X[i];
prefix[i]=prefix[i-1]+X[i];
}
while(p<k){
s=(p+k+1)/2;
//cout<<p<<' '<<s<<' '<<k<<'\n';
if(f(s,B,R)){
p=s;
}
else k=s-1;
}
return p;
}/*
int main(){
int n1,n2,b;
int X[100];
cin>>n1>>n2;
for(int i=0;i<n1;i++) cin>>X[i];
cin>>b;
cout<<besthub(n1,n2,X,b)<<'\n';
}*/
# | 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... |