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