# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
737210 | ETheBest3 | Rice Hub (IOI11_ricehub) | C++17 | 16 ms | 2496 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"
#define lli long long
const lli MAXN=100005;
lli pref[MAXN];
int besthub(int R, int L, int X[], long long B)
{
for(lli i=0; i<R; i++)
{
if(i==0)pref[i]=X[i];
else pref[i]=pref[i-1]+X[i];
}
lli p1=0, p2=0, p3=0, now=0, sum=0, ans=0;
for(; p2<R; p2++)
{
now=pref[p2]/(p2+1);
while(p3<p2 and X[p3+1]<=now)p3++;
sum=(pref[p2]-pref[p3])-now*(p2-p3)+now*(p3+1)-pref[p3];
//std::cout<<p3<<" "<<p2<<" "<<sum<<" "<<now<<std::endl;
if(sum>B)break;
}
if(sum<=B)return p2;
ans=p2;
p2--;
//std::cout<<p3<<" "<<p2<<" "<<sum<<" "<<ans<<std::endl;
for(p1=0; p1<R; p1++)
{
if(p2<p1+1)p2=p1+1;
for(; p2<R; p2++)
{
//if((pref[p2]-pref[p1])%(p2-p1)>(p2-p1)/2)now=(pref[p2]-pref[p1])/(p2-p1)+1;
now=now=(pref[p2]-pref[p1])/(p2-p1);
//std::cout<<now<<"\n";
while(p3<p2 and X[p3+1]<=now)p3++;
sum=(pref[p2]-pref[p3])-now*(p2-p3)+now*(p3-p1)-(pref[p3]-pref[p1]);
//std::cout<<p2<<" "<<p3<<" "<<p1<<" "<<sum<<"\n";
if(sum>B)break;
}
if(ans<p2-p1-1)ans=p2-p1-1;
//std::cout<<p1<<" "<<p2<<" "<<ans<<std::endl;
p2--;
}
return ans;
}
Compilation message (stderr)
# | 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... |