제출 #60837

#제출 시각아이디문제언어결과실행 시간메모리
60837Vahan쌀 창고 (IOI11_ricehub)C++17
17 / 100
33 ms4608 KiB
#include "ricehub.h" #include<algorithm> using namespace std; int x[200000],su[200000]; int bin(int l,int r,int v) { if(l==r) return l; if(l==r-1) { if(x[r]<=v) return r; else return l; } int mid=(l+r)/2; if(x[mid]<=v) return bin(mid,r,v); else return bin(l,mid-1,v); } int pat(int l,int r) { int mig=(su[r]-su[l]+x[l])/(r-l+1); int f,e; if((su[r]-su[l]+x[l])%(r-l+1)==0) { e=bin(l,r,mig); return (e-l+1)*mig+su[l]-x[l]+su[r]-(r-e)*mig-2*su[e]; } else { e=bin(l,r,mig); f=bin(l,r,mig+1); return min((e-l+1)*mig+su[l]-x[l]+su[r]-(r-e)*mig-2*su[e],(f-l+1)*(mig+1)+su[l]-x[l]+su[r]-(r-f)*(mig+1)-2*su[f]); } } int besthub(int R, int L, int X[], long long B) { for(int r=0;r<R;r++) { x[r]=X[r]; if(r==0) su[r]=X[r]; else su[r]=su[r-1]+X[r]; } int l=0; int q,an=-1; for(int r=0;r<R;r++) { q=pat(l,r); while(q>B) { l++; q=pat(l,r); } an=max(an,r-l+1); } return an; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...