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;
using ll = long long;
#define MAXN (1000005)
int besthub(int R, int L, int X[], long long B){
ll maximum = 0;
for(ll pos = 0;pos < R;pos++){
ll Lptr = pos;
ll Rptr = pos;
ll curcost = 0;
while(Lptr > 0 && curcost + abs(X[pos] - X[Lptr - 1]) <= B){
curcost += abs(X[pos] - X[Lptr - 1]);
Lptr--;
}
while(Rptr < R - 1 && curcost + abs(X[pos] - X[Rptr + 1]) <= B){
curcost += abs(X[pos] - X[Rptr + 1]);
Rptr++;
}
while(Rptr < R - 1 && abs(X[pos] - X[Lptr]) > abs(X[pos] - X[Rptr + 1])){
curcost -= abs(X[pos] - X[Lptr]);
curcost += abs(X[pos] - X[Rptr + 1]);
Lptr++;
Rptr++;
while(Rptr < R - 1 && curcost + abs(X[pos] - X[Rptr + 1]) <= B){
curcost += abs(X[pos] - X[Rptr + 1]);
Rptr++;
}
}
maximum = max(maximum,Rptr - Lptr + 1);
}
return maximum;
}
# | 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... |