제출 #1327663

#제출 시각아이디문제언어결과실행 시간메모리
1327663itzmanu구경하기 (JOI13_watching)C++20
0 / 100
1 ms332 KiB
#include <bits/stdc++.h>
using namespace std;

#define nitro ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define vi vector<int>
#define spc ' '
#define yes "YES"
#define no "NO"
#define endl "\n"
const int INF = 1e18;
const int maxn = 2e5 + 5;
const int mod = 1000000000;
const int logn = 20;

void solve() {
	int n, p, q; cin >> n >> p >> q;
	vi a(n);
	for(auto &i : a) cin >> i;
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	n = a.size();
	if(p + q >= n) {
		cout << 1;
		return;
	}
	int l = 0, r = a[n - 1] - a[0];
	auto check = [a, n, p, q](int w) {
		vector<vi> dp(p + 1, vi(q + 1, 0));
		int nextp[n + 1], nextq[n + 1];
		int r1 = 0, r2 = 0;
		for(int i = 0; i < n; i++) {
			while(r1 < n and a[r1] < a[i] + w) r1++;
			nextp[i] = r1;
			while(r2 < n and a[r2] < a[i] + 2LL * w) r2++;
			nextq[i] = r2;
		}
		nextp[n] = nextq[n] = n;
		for(int i = 0; i <= p; i++) {
			for(int j = 0; j <= q; j++) {
				if(i > 0) {
					dp[i][j] = max(dp[i][j], nextp[dp[i - 1][j]]);
				}
				if(j > 0) {
					dp[i][j] = max(dp[i][j], nextq[dp[i][j - 1]]);
				}
				if(dp[i][j] >= n) return true;
			}
		}
		return false;
	};
	while(l < r) {
		int m = (l + r) / 2;
		if(check(m)) {
			r = m - 1;
		} else {
			l = m + 1;
		}
	}
	cout << l;
}

signed main() {
	// freopen("disrupt.in", "r", stdin);
	// freopen("disrupt.out", "w", stdout);
	nitro
	int t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++) {
		// cout << "Case #" << i << ": ";
		solve();
		cout << endl;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...