#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p, lim; cin >> n >> p >> lim;
  vector<int> x(n);
  for(int i = 0; i < n; i++){
    cin >> x[i];
  }
  x.push_back(1e18);
  sort(x.begin(), x.end());
  p = min(p, n);
  lim = min(lim, n);
  int low = 1;
  int top = 1e9;
  int ans = 0;
  while(low <= top){
    int mid = (low + top)/2;
    vector<vector<int>> dp(n+1, vector<int>(n+1, 1e18));
    dp[0][0] = 0;
    queue<pair<int, pair<int, int>>> q;
    queue<pair<int, pair<int, int>>> q1;
    for(int i = 0; i <= n; i++){
      while(q.size() > 0){
        pair<int, pair<int, int>> f = q.front();
        if(f.first < x[i]){
          q.pop();
          dp[i][f.second.first] = min(f.second.second, dp[i][f.second.first]);
        }else{
          break;
        }
      }
      while(q1.size() > 0){
        pair<int, pair<int, int>> f = q1.front();
        if(f.first < x[i]){
          q1.pop();
          dp[i][f.second.first] = min(f.second.second, dp[i][f.second.first]);
        }else{
          break;
        }
      }
      for(int y = 0; y <= n; y++){
        //1
        q.push({x[i] + mid-1, {y+1, dp[i][y]}});
        //2
        q1.push({x[i] + 2*mid-1, {y, dp[i][y]+1}});
      }
    }
    bool ns = false;
    for(int i = 0; i <= p; i++){
      if(dp[n][i] <= lim){
        ns = true;
      }
    }
    if(ns){
      top = mid-1;
      ans = mid;
    }else{
      low = mid+1;
    }
  }
  cout << ans << "\n";
  return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |