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;
int n,p,q,s = 1, e= 1e9 + 5, ans = 1e9 + 5;
int dp[2005][2005], A[2005];
bool c(int x){
for(int i=1;i<=n;i++){
int l = 1, r = 1;
while(A[i] - A[l] >= x)l++;
while(A[i] - A[r] >= 2*x)r++;
for(int j=0;j<=p;j++){
if(j == 0)dp[i][j] = dp[r-1][j] + 1;
else dp[i][j] = min(dp[l-1][j-1], dp[r-1][j] + 1);
}
}
return dp[n][p] <= q;
}
int main(){
cin >> n >> p >> q;
for(int i=1;i<=n;i++)cin >> A[i];
if(p + q >= n){
cout << 1;
exit(0);
}
sort(A+1, A+n+1);
while(s <= e){
int m = (s + e)/2;
memset(dp, 0, sizeof(dp));
if(c(m)){
ans = m;
e = m - 1;
}
else s = m + 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |