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<algorithm>
using namespace std;
int besthub(int r, int l, int x[], long long b){
int duz=0;
long long cena=0;
int res=0;
for(int i=0;i<r;i++){
while(i-duz-1>=0 && i+duz+1<r){
if(cena+abs(x[i]-x[i-duz-1])+abs(x[i]-x[i+duz+1])>b) break;
cena+=abs(x[i]-x[i-duz-1])+abs(x[i]-x[i+duz+1]);
duz++;
}
res=max(res,2*duz+1);
if(i-duz-1>=0){
if(cena+abs(x[i]-x[i-duz-1])<=b) res=max(res,2*duz+2);
}
if(i+duz+1<r){
if(cena+abs(x[i]-x[i+duz+1])<=b) res=max(res,2*duz+2);
}
if(i<r-1 && duz>0){
cena+=x[i+1]-x[i];
cena-=abs(x[i+1]-x[i-duz]);
cena-=abs(x[i+1]-x[i-duz+1]);
duz--;
}
}
return res;
}
# | 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... |