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 "ricehub.h"
using namespace std;
#define ll long long
int besthub(int R, int L, int X[], long long B) {
int ans=0;
long long cost=0;
for (int i=0; i<R; i++){
cost=0;
int pans=0, pos;
for (int j=0; j<R; j++){
if (X[j] == X[i]){
pos=j;
break;
}
}
int pl=pos-1, pr=pos;
while(1){
if (pl<0 && pr>=R) break;
else if (pr>=R){
ll tl = X[i] - X[pl];
if (cost + tl <= B){
cost+=tl;
pans++;
pl--;
}else break;
}else if (pl<0){
ll tr = X[pr] - X[i];
if (cost + tr <= B){
cost+=tr;
pans++;
pr++;
}else break;
}else{
ll tr=X[pr] - X[i], tl=X[i] - X[pl];
if (tr<tl){
if (cost + tr <= B){
cost+=tr;
pans++;
pr++;
}else break;
}else{
if (cost + tl <= B){
cost+=tl;
pans++;
pl--;
}else break;
}
}
}
ans=max(ans, pans);
}
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... |