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 = 2010, MX = 1e9;
int n, p, q, arr[N], dp[N][N], go[N][2]; // min_q, max_pos_p, max_pos_j
bool check(int w){
int a = 1, b = 1;
for(int i = 1; i <= n; i++){
while(a < i && arr[a] + w <= arr[i]) a++;
while(b < i && arr[b] + 2*w <= arr[i]) b++;
go[i][0] = a - 1, go[i][1] = b - 1;
}
int res = MX;
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++){
dp[i][j] = MX;
if(j>0) dp[i][j] = min(dp[i][j], dp[go[i][0]][j - 1]);
dp[i][j] = min(dp[i][j], dp[go[i][1]][j] + 1);
if(i==n) res = min(res, dp[i][j]);
// cout << dp[i][j] << ' ';
}
// cout << '\n';
}
return (res <= q);
}
int main(){
cin >> n >> p >> q;
for(int i = 1; i <= n; i++) cin >> arr[i];
if(p + q >= n){
cout << 1;
return 0;
}
sort(arr+1, arr+n+1);
int l = 1, h = MX, ans = MX;
while(l <= h){
int mid = ((l+h)>>1);
if(check(mid)){
ans = min(ans, mid);
h = mid - 1;
}else
l = mid + 1;
}
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |