#include <bits/stdc++.h>
using namespace std;
bool check(int k, int X[], vector<long long>& pref, int R, long long B) {
long long best = LLONG_MAX;
for (int l = 1; l + k - 1 <= R; l++) {
int r = l + k - 1;
int s = l - 1;
int t = r - 1;
int p = (s + t) / 2;
long long left = 1LL * (p - s) * X[p] - (pref[p] - pref[s]);
long long right = (pref[t+1] - pref[p+1]) - 1LL * (t - p) * X[p];
long long cost = left + right;
best = min(best, cost);
}
return best <= B;
}
long long besthub(int R, int L, int X[], long long B) {
vector<long long> pref(R + 1, 0);
for (int i = 1; i <= R; i++)
pref[i] = pref[i-1] + X[i-1];
int lo = 1, hi = R, ans = 0;
while (lo <= hi) {
int mid = (lo + hi) / 2;
if (check(mid, X, pref, R, B)) {
ans = mid;
lo = mid + 1;
} else hi = mid - 1;
}
return ans;
}
| # | 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... |