This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 2e3+10;
const int INF = 1e9+7;
int a[N];
int dp[N][N];
int main() {
ios_base::sync_with_stdio();
cin.tie(0);
int n, p, q;
cin >> n >> p >> q;
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
if(p+q >= n) {
cout << "1";
return 0;
}
sort(a+1, a+n+1);
int l = 1, r = INF, w = INF;
while(l <= r) {
int mid = (l+r)/2;
int point_p = 1, point_q = 1;
for(int i = 1; i <= n; i++) {
while(a[i]-a[point_p] >= mid) {
point_p++;
}
while(a[i]-a[point_q] >= 2*mid) {
point_q++;
}
for(int j = 0; j <= p; j++) {
dp[i][j] = INF;
if(j) {
dp[i][j] = min(dp[i][j], dp[point_p-1][j-1]);
}
dp[i][j] = min(dp[i][j], dp[point_q-1][j]+1);
}
}
int res = INF;
for(int i = 0; i <= p; i++) {
res = min(res, dp[n][i]);
}
if(res > q) {
l = mid+1;
}
else {
r = mid-1;
w = min(w, mid);
}
}
cout << w;
return 0;
}
/*
3 1 1
2
11
17
13 3 2
33
66
99
10
83
68
19
83
93
53
15
66
75
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |