#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const int inf = 1e9;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, p, q; cin>>n>>p>>q;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++){
cin>>a[i];
}
sort(a.begin() + 1, a.end());
vector<int> :: iterator it;
p = min(p, n);
vector<vector<int>> dp(n + 1, vector<int>(p + 1));
for (int j = 0; j <= p; j++) dp[0][j] = 0;
auto check = [&](int w){
for (int i = 1; i <= n; i++){
for (int j = 0; j <= p; j++){
dp[i][j] = inf;
}
}
for (int i = 1; i <= n; i++){
it = lower_bound(a.begin() + 1, a.end(), a[i] - w + 1);
int t1 = (int) (it - a.begin()) - 1;
it = lower_bound(a.begin() + 1, a.end(), a[i] - 2 * w + 1);
int t2 = (int) (it - a.begin()) - 1;
for (int j = 0; j <= p; j++){
if (j < p) dp[i][j + 1] = min(dp[i][j + 1], dp[t1][j]);
dp[i][j] = min(dp[i][j], dp[t2][j] + 1);
}
}
return dp[n][p] <= q;
};
int l = 1, r = inf;
while (l + 1 < r){
int m = (l + r) / 2;
if (check(m)){
r = m;
}
else {
l = m + 1;
}
}
if (check(l)) r = l;
cout<<r<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |