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 a[2005],dp[2005][2005],large_range[2005],small_range[2005];
int main(){
ios::sync_with_stdio(false);
int n,p,q;
cin >> n >> p >> q;
for (int i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+1+n);
int L=1,R=1000000000;
while (L < R){
int mid=(L+R)/2;
int ptrL=0,ptrS=0;
for (int i=1;i<=n;i++){
while (a[i]-a[ptrL+1] >= mid*2) ptrL++;
while (a[i]-a[ptrS+1] >= mid) ptrS++;
large_range[i]=ptrL; small_range[i]=ptrS;
}
for (int i=0;i<=n;i++){
for (int j=0;j<=min(n,q);j++){
dp[i][j]=1e9;
}
}
for (int i=0;i<=min(n,q);i++) dp[0][i]=0;
for (int i=1;i<=n;i++){
for (int j=0;j<=min(n,q);j++){
dp[i][j]=dp[small_range[i]][j]+1;
if (j != 0) dp[i][j]=min(dp[i][j],dp[large_range[i]][j-1]);
}
}
if (dp[n][min(n,q)] <= p) R=mid;
else L=mid+1;
}
cout << L << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |