# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1027679 | vjudge1 | 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>
#include "ricehub.h"
using namespace std;
const long long MAX=1e5+10;
long long pref[MAX];
vector<long long> niza;
long long budget;
bool can(long long x)
{
for(long long i=0; i<=niza.size()-x; i++)
{
long long idx=(i+i+x)/2;
long long pt=niza[idx];
long long l=pt*(idx-i)-(pref[idx]-pref[i]+niza[i]-niza[idx]);
long long r=(pref[i+x-1]-pref[idx]+niza[idx])-pt*(i+x-idx);
//cout<<"for: "<<i+1<<" "<<i+x<<" lr is: "<<l<<" "<<r<<" "<<budget<<endl;
if(l+r<=budget)return true;
}
return false;
}
long long besthub(long long R, long long L, long long X[], long long B)
{
budget=B;
for(long long i=0; i<R; i++)niza.push_back(X[i]);
pref[0]=X[0];
for(long long i=1; i<R; i++)pref[i]=pref[i-1]+X[i];
long long b=0;
long long e=R;
long long res=0;
while(b<=e)
{
long long mid=(b+e)/2;
if(can(mid))
{
res=mid;
b=mid+1;
}
else e=mid-1;
}
return res;
}
/*int main()
{
int R,L,B;
cin>>R>>L>>B;
int X[R];
budget=B;
for(int i=0; i<R; i++)cin>>X[i];
for(int i=0; i<R; i++)niza.push_back(X[i]);
pref[0]=X[0];
for(int i=1; i<R; i++)pref[i]=pref[i-1]+X[i];
int b=0;
int e=R;
int res=0;
while(b<=e)
{
int mid=(b+e)/2;
cout<<"mid: "<<mid<<endl;
if(can(mid))
{
res=mid;
b=mid+1;
}
else e=mid-1;
}
cout<<res<<endl;
return 0;
}
5 20 6
1 2 10 12 14*/