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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool check(int dis, int n, vector < ll > &pre, vector < ll > &x, ll B) {
    ll ans = 1e16;
    for (int l = 1; l + dis - 1 <= n; l++) {
        int r = l + dis - 1;
        int med = (l + r) >> 1; // x[l] -> x[r] => x[l] -> x[med] and x[med] -> x[r]
        ll mb = x[med] * (med - l + 1) - (pre[med] - pre[l - 1]) + (pre[r] - pre[med - 1]) - x[med] * (r - med + 1);
        ans = min(ans, mb);
    }
    return ans <= B;
}
int besthub(int R, int L, int X[], ll B) {
    int n = R;
    vector < ll > pre(n + 1), x(n + 1);
    pre[0] = 0;
    for (int i = 1; i <= n; i++) {
        x[i] = 1LL * X[i - 1];
        pre[i] = pre[i - 1] + x[i];
    }
    int l = 1, r = n;
    while(r - l > 1) {
        int mid = (l + r) >> 1;
        if (check(mid, n, pre, x, B))
            l = mid;
        else
            r = mid - 1;
    }
    if (check(r, n, pre, x, B))
        return r;
    else if (check(l, n, pre, x, B))
        return l;
    else
        return 0;
}
| # | 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... |