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>
#include <cstdlib>
#define maxrice 100005
using namespace std;
long long sum[maxrice],l,r,ans;
int besthub(int R, int L, int x[], long long B)
{
for(int i=0;i<R;i++)sum[i]=x[i];
for(int i=0;i<R-1;i++)sum[i+1]+=sum[i];
// for(int i=0;i<R;i++)cout<<x[i]<<"\t";cout<<endl;
// for(int i=0;i<R;i++)cout<<sum[i]<<"\t";cout<<endl;
l=0;r=0;ans=-1;
while(l<R&&r<R)
{
long long mid=(x[l]+x[r])/2;//倉之位置
// cout<<l<<","<<r<<","<<mid<<"\t";
long long count;
count=0;
// cout<<count<<",";
for(int i=l;i<=r;i++)if(x[i]<mid)count+=mid-x[i];
else count+=x[i]-mid;
// cout<<count<<endl;
if(count<=B)
{
if(ans==-1||r-l+1>ans)ans=r-l+1;
r++;
}
else l++;
if(l>r)r++;
}
return ans;
}
# | 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... |