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;
int besthub(int R, int L, int X[], long long B){
long long sum[R+2], a[R+2];
sum[0] = 0, a[0] = 0;
for (int i = 1; i <= R; i++) a[i] = X[i-1], sum[i] = sum[i-1] + a[i];
int ans = 1;
for (int l = 1; l <= R; l++) {
for (int r = l+ans; r <= R; r++){
int mid = (l+r) >> 1;
long long costleft = (mid-l)*a[mid] - (sum[mid-1]-sum[l-1]);
long long costright = (sum[r]-sum[mid]) - (r-mid)*a[mid];
if(costleft + costright <= B) {ans = max(ans, r-l+1); continue;}
break;
}
}
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... |