#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
vector<ll> a(n + 1);
a[0] = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
ll l = 0, r = 1e9 + 1;
while(l < r) {
ll mid = (l + r) / 2;
int dp[p + 1][q + 1] {};
for(int i = 0; i <= p; i++) {
for(int j = 0; j <= q; j++) {
if(i - 1 >= 0) {
int x = dp[i - 1][j];
ll X = a[x + 1] + mid - 1;
int x1 = upper_bound(a.begin(), a.end(), X) - a.begin() - 1;
dp[i][j] = max(dp[i][j], x1);
}
if(j - 1 >= 0) {
int y = dp[i][j - 1];
ll Y = a[y + 1] + mid * 2 - 1;
int y1 = upper_bound(a.begin(), a.end(), Y) - a.begin() - 1;
dp[i][j] = max(dp[i][j], y1);
}
}
}
if(dp[p][q] == n) r = mid;
else l = mid + 1;
}
cout << l << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |