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"
bool can(int g, int N, long long S[], int X[], long long B)
{
for(int l=1; l<=N-g+1; ++l)
{
//[l, r]
int r = l+g-1;
int m = (l+r)/2;
//[l, m-1]
long long lsum = (long long)(m-l)*X[m] - (S[m-1] - S[l-1]);
//[m+1, r]
long long rsum = (S[r] - S[m]) - (long long)(r-m)*X[m];
if(lsum+rsum <= B) return true;
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
long long *S = new long long[R+1];
S[0] = 0;
for(int i=1; i<=R; ++i)
S[i] = S[i-1] + X[i-1];
int lo = 0; //pos
int hi = R+1; //impos
while(lo+1!=hi)
{
int mi = (lo+hi)/2;
if(can(mi, R, S, X-1, B)) lo = mi; //tweak, make X 1-indexed
else hi = mi;
}
return lo;
}
# | 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... |