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 <iostream>
#include "ricehub.h"
typedef long long ll;
int besthub(int n, int l, int a[], long long b) {
int answer = 0;
ll sum[n + 1] = {};
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i - 1];
}
auto cost = [&](int l, int r) {
int mid = (l + r) / 2;
return sum[r] - sum[mid] - (ll) (r - mid) * a[mid - 1] + (ll) (mid - l + 1) * a[mid - 1] - (sum[mid] - sum[l - 1]);
};
for (int i = 1, j = 1; i <= n; i++) {
while (j <= n && cost(i, j) <= b) {
j++;
}
answer = std::max(answer, j - i);
}
return answer;
}
# | 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... |