# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1100323 | mm77 | Rice Hub (IOI11_ricehub) | C++14 | 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 <bits/stdc++.h>
using namespace std;
const int N=1e5+3;
long long r,l,b,x[N];
bool ok(int mid)
{
long long left=0,right=mid-1,sr=(left+right)/2,res=0;
for(int i=left;i<=right;i++)
{
res+=abs(x[i]-x[sr]);
}
while(right<r)
{
if(res<=b)return true;
res+=(sr-left+1)*(x[sr+1]-x[sr]);
res-=(right-sr)*(x[sr+1]-x[sr]);
res-=x[sr+1]-x[left];
res+=x[right+1]-x[sr+1];
sr++,right++,left++;
}
return false;
}
int besthub(long long r2,long long l2,long long x2[],long long b2)
{
r=r2,l=l2,b=b2;
for(int i=0;i<r;i++)x[i]=x2[i];
int pocz=1,kon=r+1;
while(pocz+1<kon)
{
int mid=(pocz+kon)/2;
if(ok(mid))pocz=mid;
else kon=mid;
}
return pocz;
}