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;
#define ar array
const int N = 2e3 + 5;
int a[N], n, p, q;
int dp[N][N], pw[N], p2w[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>p>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
} sort(a + 1, a + n + 1);
p = min(p, n), q = min(q, n);
auto check = [&](int w){
memset(dp, 127, sizeof dp);
memset(pw, -1, sizeof pw);
memset(p2w, -1, sizeof p2w);
for(int i=1;i<=n;i++){
for(int j=i-1;j>0;j--){
if(a[i] - a[j] + 1 > w && pw[i] == -1) pw[i] = j;
if(a[i] - a[j] + 1 > 2 * w && p2w[i] == -1) p2w[i] = j;
} if(pw[i] == -1) pw[i] = 0;
if(p2w[i] == -1) p2w[i] = 0;
}
for(int i=0;i<N;i++) dp[0][i] = 0;
for(int i=1;i<=n;i++){
for(int j=0;j<=n;j++){
if(j > 0) dp[i][j] = min(dp[i][j], dp[pw[i]][j - 1]);
dp[i][j] = min(dp[i][j], dp[p2w[i]][j] + 1);
}
}
return (dp[n][p] <= q);
};
int l = 1, r = 1e9;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
//~ cout<<check(l)<<" ";
cout<<l<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |