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;
bool Check(int num, int R, int L, int X[], long long B) {
ll *a = new ll[R + 1];
ll *s = new ll[R + 1];
for (int i = 1; i <= R; ++i) {
a[i] = X[i - 1];
s[i] = s[i - 1] + a[i];
}
for (int i = 1; i <= R - num + 1; ++i) {
int mid = (i + (i + num - 1)) / 2;
if ((s[i + num - 1] - s[mid]) - (i + num - 1 - mid) * a[mid] + (mid - i + 1) * a[mid] - (s[mid] - s[i - 1]) <= B) {
return true;
}
}
return false;
}
int besthub(int R, int L, int X[], long long B)
{
int l = 1, m, h = R;
while (l <= h) {
m = (l + h) / 2;
if (Check(m, R, L, X, B)) {
l = m + 1;
} else {
h = m - 1;
}
}
return h;
}
# | 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... |