#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n);
for(auto &x:a) cin >> x;
sort(a.begin(), a.end());
if (n <= p + q) {
cout << "1\n";
return 0;
}
int l = 1, r = 1e9;
int ans = INT_MAX;
while (r - l >= 0) {
int m = (l + r) / 2;
vector<vector<int>> dp(n, vector<int>(p + 1, 0));
int pp = 0, qp = 0;
for (int i = 0; i < n; i++) {
while(a[i] - a[pp] >= m) pp++;
while(a[i] - a[qp] >= 2 * m) qp++;
for (int j = 0; j <= p; j++) {
if (j == 0) {
if (qp == 0)
dp[i][j] = 1;
else
dp[i][j] = dp[qp - 1][j] + 1;
} else if (pp == 0)
dp[i][j] = 0;
else if (qp == 0)
dp[i][j] = min(dp[pp - 1][j - 1], 1);
else
dp[i][j] = min(dp[pp - 1][j - 1], dp[qp - 1][j] + 1);
}
}
int mini = *min_element(dp[n - 1].begin(), dp[n - 1].end());
if (mini <= q) {
r = m - 1;
ans = min(ans, m);
} else {
l = m + 1;
}
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |