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>
#define ll long long
using namespace std;
const int nax = 1e5 + 5;
ll n, maxi, a[nax], pref[nax], suff[nax];
ll b;
bool chk(int x) {
	if (x > n) return false;
	if (x <= 1) return true;
	for (int i = 1; i <= n - x + 1; ++i) {
		int l = i, r = i + x - 1;
		int median = l + (r - l) / 2;
		ll num_left = max(0LL, (median - 1 - l) + 1LL);
		ll num_right = max(0LL, r - (median + 1) + 1LL);
		ll cost_left = 1LL * a[median] * num_left - (1LL * pref[median - 1] - pref[l - 1]);
		ll cost_right = 1LL * suff[median + 1] - suff[r + 1] - 1LL * a[median] * num_right;
		if (cost_left + cost_right <= b) return true;
	}
	return false;
}
int solve() {
	for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i];
	for (int i = n; i >= 1; --i) suff[i] = suff[i + 1] + a[i];
	int l = 1, r = n;
	while (r >= l) {
		int mid = (l + r) / 2;
		bool status = chk(mid);
		if (status) {
			if (chk(mid + 1)) l = mid + 1;
			else {
				return mid;
			}
		}
		else {
			r = mid - 1;
		}
	}
	return 1;
}
int besthub(int R, int L, int X[], long long B) {
	n = R;
	maxi = L;
	for (int i = 0; i < R; ++i) a[i + 1] = X[i];
	b = B;
	return solve();
}
| # | 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... |