Submission #64621

#TimeUsernameProblemLanguageResultExecution timeMemory
64621gnoorRice Hub (IOI11_ricehub)C++17
100 / 100
32 ms16760 KiB
#include "ricehub.h" long long b; long long pos[100100]; long long qs[100100]; int n; bool work(int num) { int x=num/2; int hub; long long cur; for (int i=num;i<=n;i++) { hub=i-x; cur=qs[i]-qs[hub]-pos[hub]*x; cur+=pos[hub]*(num-x)-qs[hub]+qs[i-num]; if (cur<=b) return true; } return false; } int besthub(int R, int L, int X[], long long B) { b=B; n=R; for (int i=1;i<=n;i++) { qs[i]=pos[i]=X[i-1]; qs[i]+=qs[i-1]; } int lo=1; int hi=R; int mid; while (lo<hi) { mid=(lo+hi+1)>>1; if (work(mid)) lo=mid; else hi=mid-1; } return lo; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...