#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int dp[N][N];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
vector<int>a(n + 1, -1e9);
for(int i = 1;i <= n;++i){
cin >> a[i];
}
sort(a.begin(), a.end());
if(p + q >= n){
cout << "1\n";
return 0;
}
else{
int l = 1, r = 1e9, ans = 1e9;
while(l <= r){
int mid = (l + r) / 2;
for(int i = 1;i < N;++i){
for(int j = 0;j < N;++j){
dp[i][j] = 1e9;
}
}
for(int i = 1;i <= n;++i){
int pos1 = lower_bound(a.begin(), a.end(), a[i] - mid + 1) - a.begin();
pos1--;
int pos2 = lower_bound(a.begin(), a.end(), a[i] - 2 * mid + 1) - a.begin();
pos2--;
for(int j = 0;j <= p;++j){
dp[i][j] = dp[pos2][j] + 1;
if(j)dp[i][j] = min(dp[i][j], dp[pos1][j - 1]);
}
}
if(dp[n][p] <= q){
ans = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
cout << ans << '\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |