Submission #969914

#TimeUsernameProblemLanguageResultExecution timeMemory
969914uriegRice Hub (IOI11_ricehub)C++17
74 / 100
14 ms5212 KiB
#include <bits/stdc++.h> #include "ricehub.h" using namespace std; typedef long long ll; /// for moondance int besthub(int R, int L, int X[], long long B){ vector<ll>x(R), p(R); for(int i=0;i<R;i++){ x[i] = X[i]; p[i] = x[i]; if(i)p[i] += p[i-1]; } ll sum = 0; int l = 1, r = R; while(l<r){ int m = (l+r+1)/2; bool ok = 0; for(int i = 0;i+m<=R; i++){ int L = i, R = i+m-1; int mid = (R+L)/2; sum = p[R] - p[mid] - (x[mid]*(R-mid)); sum += x[mid]*(mid-L+1) - (!L ? 0 : p[mid]-p[L-1]); // cout<<L<<' '<<R<<' '<<mid<<' '<<sum<<endl; if(sum <= B){ ok = 1; break; } } // cout<<m<<' '<<ok<<endl; if(ok){ l = m; } else r = m-1; } 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...