#include <bits/stdc++.h>
using namespace std;
#define ll long long
int besthub(int R, int L, int X[], ll B) {
vector<ll> coords;
int n = R;
ll b = B;
for (int i = 0; i < n; i++) coords.push_back(X[i]);
int maxAns = 0;
int l = 0, r = 0;
ll totDis = 0;
for (int i = 0; i < n; i++) {
if (i > 0) {
ll toL = max(0LL, (ll)(i - l));
ll toR = max(0LL, r - l + 1 - toL);
totDis += toL * (coords[i] - coords[i-1]) - toR * (coords[i] - coords[i-1]);
}
r = max(r, i);
while (totDis > b) {
totDis -= abs(coords[i] - coords[l]);
l++;
}
while (r < n-1 && ((abs(coords[r+1] - coords[i]) <= abs(coords[i] - coords[l]) && l < i) || (abs(coords[r+1] - coords[i]) + totDis <= b))) {
totDis += abs(coords[r+1] - coords[i]);
r++;
if (totDis > b) {
totDis -= abs(coords[i] - coords[l]);
l++;
}
}
maxAns = max(maxAns, r - l + 1);
}
return maxAns;
}
# | 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... |