이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int nax = 1e5 + 5;
int n, maxi, a[nax], pref[nax], suff[nax];
ll b;
bool chk(int x) {
	if (x > n || x < 1) return false;
	for (int i = 1; i <= n - x + 1; ++i) {
		int l = i, r = i + x - 1;
		int median = (l + r) / 2;
		// l..(median - 1)
		// (median + 1)..r
		int num_left = max(0, (median - 1 - l) + 1);
		int num_right = max(0, r - (median + 1) + 1);
		int cost_left = a[median] * num_left - (pref[median - 1] - pref[l - 1]);
		int cost_right = suff[median + 1] - suff[r + 1] - 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 0;
}
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... |