# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
687630 | beedle | Rice Hub (IOI11_ricehub) | C++17 | 0 ms | 0 KiB |
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"
#include <iostream>
int besthub(int R, int L, int X[], long long B)
{
long long cs[R];
cs[0]=X[0];
for(int i=1;i<R;i++)
cs[i]=cs[i-1]+X[i];
long long lo=1;
long long hi=R;
long long best=1;
while(lo<=hi)
{
long long mid=(lo+hi)/2;
bool possible=false;
for(int i=0;i<R;i++)
if(i+mid-1<R)
{
long long pivot=i+mid/2;
long long value=-(cs[pivot-1]-(i==0?0:cs[i-1]))+cs[i+mid-1]-cs[pivot]-X[pivot]*(i+mid-1-pivot)+X[pivot]*(pivot-1-(i-1));
if(value<=B)
possible=true;
}
if(possible)
best=mid, lo=1+mid;
else
hi=mid-1;
}
return best;
}
signed main()
{
int X[]={1,2,10,12,14};
std::cout<<besthub(5,20,X,6);
}