#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
void solve () {
int n, p, q;
cin >> n >> p >> q;
vector<int> a(n+1);
for (int i = 1; i <= n; ++i) cin >> a[i];
if (n <= p) {cout << 1; return ;}
sort(all(a));
vector<vector<int>> dp(n+1, vector<int>(n+1));
int l = 0, r = a[n];
while (l + 1 < r) {
int m = (l + r) / 2;
for (int i = 1, j = 0, k = 0; i <= n; i++) {
while (a[i] - a[j+1] >= m) j++;
while (a[i] - a[k+1] >= 2 * m) k++;
dp[i][0] = 1 + dp[k][0];
for (int s = 1; s <= p; s++) dp[i][s] = min(dp[j][s-1], 1 + dp[k][s]);
}
if (dp[n][p] <= q) r = m;
else l = m;
}
cout << r;
}
signed main() {IOS solve(); return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |