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 <bits/stdc++.h>
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
int l=1;
int r=R;
int ans=1;
while(l<=r){
int mid=(l+r)/2;
int curpos=0;
int hwl=1;
int hwr=mid-1;
long long cur=0;
int cl=0;int cr=mid-1;
for(int i=1;i<mid;++i){
cur+=X[i]-X[0];
}
// cout<<mid<<" "<<cur<<endl;
if(cur<=B){
ans=mid;
l=mid+1;
continue;
}
// cout<<"h"<<endl;
bool ok=true;
while(cr<R){
while(hwl<hwr&&curpos<cr){
cur-=(hwr-hwl)*(X[curpos+1]-X[curpos]);
hwl++;hwr--;
curpos++;
}
// cout<<cur<<" "<<hwl<<" "<<hwr<<" "<<cl<<" "<<cr<<endl;
if(cur<=B){
ok=false;
break;
}
cl++;cr++;
hwl--;hwr++;
cur-=X[curpos]-X[cl-1];
cur+=X[cr]-X[curpos];
}
if(ok){
r=mid-1;
}
else{
ans=mid;
l=mid+1;
}
}
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... |