#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 8;// Adjust N as we need nNNNn
int dp[2008][2008];
int n , q , p , a[maxn];
bool s(int w){
for(int i = 1 ; i <= n ; i++){
int s1 = lower_bound(a , a + n + 1 , a[i] - w + 1) - a - 1, s2 = lower_bound(a , a + n + 1 , a[i] - 2 * w + 1) - a - 1;
dp[i][0] = dp[s1][0] + 1;
//cout << i << ' ' << s1 << ' ' << s2 << "index\n";
for(int j = 1 ; j <= q ; j++){
dp[i][j] = min(dp[s1][j] + 1 ,dp[s2][j - 1]);
// cout << i << ' ' << j << ' ' << dp[i][j] << "\n";
}
}
return (dp[n][q] <= p );
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin >> n >> p >> q;a[0] = -2e9;
for(int i = 1 ; i <= n ; i++)cin >> a[i];
sort(a, a + n + 1);
int l = 1 , r = 1e9;
while(l < r){
int mid = (r - l) / 2 + l;
if(s(mid))r = mid;
else l = mid + 1;
}
cout << l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |