#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);
int k1 = 1, k2 = 1;
for (int i = 1; i <= n;i++) {
while (k1 < i && a[i] - a[k1] + 1 > w) k1++;
while (k2 < i && a[i] - a[k2] + 1 > 2 * w) k2++;
for (int j = 0; j <= q;j++) {
dp[i][j] = min(dp[i][j], dp[k1 - 1][j] + 1);
if (j > 0)
dp[i][j] = min(dp[i][j], dp[k2 - 1][j - 1]);
}
}
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... |