#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool comp(pair<int, int> a, int v) {return a.first < v;}
int main()
{
int n, p, q; cin >> n >> p >> q;
if ((p + q) >= n) { cout << 1; return 0; }
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) cin >> a[i].first;
sort(a.begin(), a.end());
for (int i = 0; i < n; ++i) a[i].second = i;
int s = 0, e = 1e9, ans = -1;
while (s <= e) {
int w = (s + e) / 2;
vector<vector<int>> dp;
dp.assign(p + 1, vector<int>(n + 1, 1e9));
for (int cp = 0; cp <= p; ++cp)
for (int i = n - 1; i >= 0; --i) {
if (cp > 0) {
auto it = lower_bound(a.begin(), a.end(), a[i].first + w, comp);
if (it == a.end()) dp[cp][i] = min(dp[cp][i], 0);
else dp[cp][i] = min(dp[cp][i], dp[cp - 1][(*it).second]);
}
auto it = lower_bound(a.begin(), a.end(), a[i].first + w + w, comp);
if (it == a.end()) dp[cp][i] = min(dp[cp][i], 1);
else dp[cp][i] = min(dp[cp][i], 1 + dp[cp][(*it).second]);
}
if (dp[p][0] <= q)
ans = w, e = w - 1;
else s = w + 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |