Submission #919087

#TimeUsernameProblemLanguageResultExecution timeMemory
919087AiperiiiRice Hub (IOI11_ricehub)C++14
100 / 100
12 ms6204 KiB
#include <bits/stdc++.h> #define ff first #define ss second #define pb push_back #define all(x) x.begin(),x.end() using namespace std; int besthub(int R, int L, int X[], long long B) { vector <long long> v; for(int i=0;i<R;i++)v.pb(X[i]); vector <long long> sum;long long x=0; for(int i=0;i<R;i++){ x+=v[i];sum.pb(x); } int l=0,r=R+2; while(l+1<r){ int md=(l+r)/2; bool ok=0; for(int i=0;i<R;i++){ long long x=0; long long a=0,b=0; if(md%2==1){a=md/2;b=md/2;} else {a=md/2;b=md/2-1;} if(i>a-1 && i+b<R){ long long pos=i-1; long long d=0; if(pos>=0)d+=sum[pos]; if(pos-a>=0)d-=sum[pos-a]; x+=v[i]*a-d; pos=i+b; d=sum[pos]-sum[i]; x+=d-v[i]*b; if(x<=B)ok=1; } } if(ok)l=md; else r=md; } return l; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...