#include <bits/stdc++.h>
using namespace std;
#define NMAX 1000005
#define ll long long
int v[NMAX], c[NMAX], n, a, b;
bool dp[NMAX];
bool verif(int st, int dr, int x) {
    if (dr - st + 1 > b || dr - st + 1 < a || v[dr] - v[st] > x) return false;
    return true;
}
bool check(int x) {
    for (int i = 1; i <= n; i++) dp[i] = 0, c[i] = 0;
    if (!verif(1, a, x) || !verif(n - a + 1, n, x)) return false;
    dp[0] = dp[a] = 1, c[a] = a;
    for (int i = a + 1; i <= n; i++) {
        dp[i] = verif(c[i - a] + 1, i, x);
        if (dp[i]) c[i] = i;
        else c[i] = c[i - 1];
    }
    //for (int i = 1; i <= n; i++) cout << dp[i] << " ";
    return dp[n];
}
int main() {
    cin >> n >> a >> b;
    for (int i = 1; i <= n; i++) cin >> v[i];
    sort(v + 1, v + n + 1);
    int left = 0, right = v[n] - v[1], ans = right;
    while (left <= right) {
        int mid = left + (right - left) / 2;
        if (check(mid)) {
            ans = mid;
            right = mid - 1;
        } else left = mid + 1;
    }
    cout << ans;
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |