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"
using ll = long long;
int besthub(int R, int L, int X[], ll B)
{
int low = 1;
int high = R;
while (low < high) {
int mid = (low + high+1)/2;
int l = 0;
int r = 0;
int m = (mid-1)/2;
bool good = false;
ll bot = 0;
ll top = 0;
while (r < mid) {
if (r < m) {
bot += X[r];
}
else if (r > m) {
top += X[r];
}
r++;
}
r--;
if ((m-l)*X[m]-bot + top-(r-m)*X[m] <= B) {
good = true;
}
while (r+1< R) {
bot -= X[l];
top += X[r+1];
bot += X[m];
top -= X[m+1];
r++;
l++;
m++;
if ((m-l)*X[m]-bot + top-(r-m)*X[m] <= B) {
good = true;
}
}
if (good) {
low = mid;
}
else {
high = mid-1;
}
}
return low;
}
# | 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... |