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>
using namespace std;
const int N = 2005;
int n, p, q, a[N], d1[N], d2[N], dp[N][N];
inline bool check(int w){
for(int i = 1; i <= n; i++){
d1[i] = lower_bound(a + 1, a + n + 1, a[i] - w + 1) - a;
d2[i] = lower_bound(a + 1, a + n + 1, a[i] - 2 * w + 1) - a;
}
memset(dp, 63, sizeof(dp));
for(int i = 0; i <= p; i++){
dp[0][i] = 0;
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= p; j++){
if(j > 0){
dp[i][j] = dp[d1[i] - 1][j - 1];
}
dp[i][j] = min(dp[i][j], dp[d2[i] - 1][j] + 1);
}
}
return dp[n][p] <= q;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> p >> q;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
int l = 1, r = 1e9;
while(r - l > 1){
int mid = (r + l) >> 1;
if(check(mid)){
r = mid;
}
else{
l = mid;
}
}
if(check(l)){
cout << l;
}
else{
cout << r;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |