#include <bits/stdc++.h>
using namespace std;
int besthub(int n, int m, int a[], long long b) {
vector<int> prfx(n);
prfx[0] = a[0];
for (int i = 1; i < n; ++i) {
prfx[i] = prfx[i - 1] + a[i];
}
auto getPrfx = [&](int l, int r) -> int {
if (l > r) return 0;
int left = (l == 0) ? 0 : prfx[l - 1];
int right = prfx[r];
return right - left;
};
int res = 1;
int l = 0, r = 0;
while (r < n) {
int mid = (l + r) / 2;
int s = getPrfx(l, r) - a[mid];
int s1 = getPrfx(l, mid - 1);
int s2 = getPrfx(mid + 1, r);
int d1 = mid - l;
int d2 = r - mid;
int score = s2 - 1LL * d2 * a[mid] + (1LL * d1 * a[mid] - s1);
if (score <= b) {
res = max(res, r - l + 1);
++r;
} else {
++l;
}
}
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... |