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 x[], long long b) {
std::vector<long long> a(n), pf(n);
for (int i = 0; i < n; ++i) {
a[i] = (i ? a[i - 1] : 0) + x[i];
pf[i] = (i ? pf[i - 1] : 0) + 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 + 1];
};
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... |