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 <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long llo;
#define mp make_pair
#define a first
#define b second
#define pb push_back
#include <ricehub.h>
int besthub(int nn,int coo,int tt[],llo b){
llo n=(llo)nn;
llo l,r;
llo tot=0;
llo ma=0;
llo it[n];
for(int i=0;i<n;i++){
it[i]=(llo)tt[i];
}
for(llo i=0;i<n;i++){
if(i==0){
l=0;
r=-1;
for(llo j=0;j<n;j++){
if(tot+it[j]-it[0]<=b){
tot+=(it[j]-it[0]);
r+=1;
}
else{
break;
}
}
ma=max(ma,r-l+1);
}
else{
if(it[i]==it[i-1]){
continue;
}
tot+=abs(it[i]-it[i-1])*abs(l-i);
tot-=abs(it[i]-it[i-1])*abs(r-i+1);
llo llp=l;
for(int j=llp;j<i;j++){
if(tot>b){
tot-=abs(it[j]-it[i]);
l+=1;
}
else{
break;
}
}
for(llo j=r+1;j<n;j++){
if(abs(it[j]-it[i])<=abs(it[i]-it[l])){
r+=1;
tot+=abs(it[j]-it[i]);
if(tot>b){
l+=1;
tot-=abs(it[i]-it[l-1]);
if(tot>b){
while(true){
continue;
}
}
}
}
else if(abs(it[j]-it[i])+tot<=b){
r+=1;
tot+=abs(it[j]-it[i]);
}
else{
break;
}
}
ma=max(ma,r-l+1);
}
}
return ma;
}
/*int main(){
llo cc[5];
cc[0]=1;
cc[1]=2;
cc[2]=10;
cc[3]=12;
cc[4]=14;
cout<<besthub(5,20,cc,(llo)6)<<endl;
return 0;
}*/
# | 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... |