#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ertunt return
#define vodka void
using namespace std;
int main() {
    ll n, p, q;
    cin >> n >> p >> q;
    if (p + q >= n) {
        cout << 1;
        ertunt 0;
    }
    ll a[n];
    for (ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a+n);
    ll dp[p+1][q+1];
    ll l = 1, r = 1e9+5;
    while (l < r) {
        ll m = (l+r)/2;
        memset(dp,0,sizeof dp);
        for(ll i = 0; i <= p; i++){
            for(ll j = 0; j <= q; j++){
                if(i>0){
                    if(dp[i-1][j]==n) dp[i][j]=n;
                    else{
                        ll R = lower_bound(a, a+n, a[dp[i-1][j]]+m)-a;
                        dp[i][j] = max(dp[i][j], R);
                    }
                }
                if(j>0){
                    if(dp[i][j-1]==n) dp[i][j]=n;
                    else{
                        ll R = lower_bound(a, a+n, a[dp[i][j-1]]+2*m)-a;
                        dp[i][j] = max(dp[i][j], R);
                    }
                }
            }
        }
        if(dp[p][q]==n) r=m;
        else l=m+1;
    }
    cout << l;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |