#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define int i64
#define vi vector<int>
#define vvi vector<vi>
#define vb vector<bool>
#define fi first
#define se second
#define pii pair<int, int>
#define sz(x) (int)(x).size()
inline void solve(){
int n, p, q;
cin >> n >> p >> q; // max n kadar p ve q yeterli
p = min(n, p), q = min(n, q);
vi a(n);
for(int &i : a){
cin >> i;
}
sort(a.begin(), a.end());
auto check = [&](int w) -> bool {
vvi dp(n + 1, vi(p + 1, INT32_MAX)); // [n, p] -> #q
dp[0][0] = 0;
for(int i = 0; i < n; i++){
int to_p = upper_bound(a.begin(), a.end(), a[i] + w - 1) - a.begin(), to_q = upper_bound(a.begin(), a.end(), a[i] + 2 * w - 1) - a.begin();
//cout << "i: " << i << " to_p: " << to_p << " to_q: " << to_q << " w: " << w << "\n";
for(int j = 0; j <= p; j++){
if(j < p){
dp[to_p][j + 1] = min(dp[to_p][j + 1], dp[i][j]);
}
dp[to_q][j] = min(dp[to_q][j], dp[i][j] + 1);
}
}
for(int i = 0; i <= p; i++){
//cout << "p: " << i << " q: " << dp[n][i] << "\n";
if(dp[n][i] <= q) return true;
}
return false;
};
auto bs = [&]() -> int {
int lo = 1, hi = 1e9, ret = lo, mid;
while(hi >= lo){
mid = lo + (hi - lo) / 2;
if(check(mid)){
hi = mid - 1;
ret = mid;
}
else{
lo = mid + 1;
}
}
return ret;
};
cout << bs() << "\n";
return;
}
signed main(){
//ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |