#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
#define all(x) x.begin(), x.end()
const int inf = 2e9 + 5;
void solve() {
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n);
for (int i = 0; i < n;i++)
cin >> a[i];
if (p + q >= n)
return (void)(cout << 1);
// a.insert(a.begin(), 0);
a.push_back(0);
sort(a.begin(), a.end());
auto f = [&](int w) {
vector dp(n + 1, vector(q + 1, p + 5));
dp[0].assign(q + 1, 0);
multiset<ar<int, 2>> sm[q + 1], big[q + 1];
for (int i = 1; i <= n;i++) {
for (int j = 0; j <= q;j++) {
sm[j].insert({dp[i - 1][j], i});
big[j].insert({dp[i - 1][j], i});
while (!sm[j].empty()) {
auto [x, id] = *sm[j].begin();
if (a[i] - a[id] + 1 <= w) break;
sm[j].erase(sm[j].begin());
}
while (!big[j].empty()) {
auto [x, id] = *big[j].begin();
if (a[i] - a[id] + 1 <= w * 2) break;
big[j].erase(big[j].begin());
}
if (!sm[j].empty())
dp[i][j] = min(dp[i][j], (*sm[j].begin())[0] + 1);
if (j > 0 && !big[j - 1].empty())
dp[i][j] = min(dp[i][j], (*big[j - 1].begin())[0]);
}
}
int ans = *min_element(dp[n].begin(), dp[n].end());
return ans;
};
int l = 1, r = 1e9, ans = 1e9;
while (l <= r) {
int m = (l + r) / 2;
if (f(m) <= p) r = m - 1, ans = m;
else l = m + 1;
}
cout << ans;
}
signed main() {
ios :: sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
cout << "\n";
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |