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=(l+r)/2;//倉之位置
long long count;
count = x[mid]*(mid-l) - sum[mid-1] + sum[l-1] + sum[r] - sum[mid] - x[mid]*(r-mid);
if(count<=B)
{
if(r-l+1>ans)ans=r-l+1;
r++;
}
else l++;
}
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... |