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"
#include <bits/stdc++.h>
int besthub(int n, int L, int *a, long long b) {
std::vector<long long> pf(n);
for (int i = 0; i < n; ++i) {
pf[i] = (i ? pf[i - 1] : 0LL) + a[i];
}
auto qry = [&](int l, int r) {
int md = (l + r) / 2;
return (md - l + 1) * a[md] - pf[md] + (l ? pf[l - 1] : 0LL) + pf[r] - pf[md] - (r - md) * a[md];
};
int res = 0;
for (int i = 0, j = 0; i < n; ++i) {
while (qry(j, i) > b) {
++j;
}
res = std::max(res, i - j + 1);
}
return res;
}
# | 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... |