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>
#define f0(i, n) for(int i(0); i < (n); i++)
#define f1(i, n) for(int i(1); i <= n; i++)
using namespace std;
typedef long long ll;
const int N = 2002;
int n, p, q, a[N];
int f[N][N], d1[N], d2[N];
bool solve(int w){
memset(f, -1, sizeof(f));
///sort(a + 1, a + n + 1);
f1(i, n){
d1[i] = d2[i] = 0;
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;
}
/// f[i][j];
f0(j, p + 1) f[0][j] = q;
f1(i, n){
f0(j, p + 1){
if(j > 0){
int k1 = d1[i];
f[i][j] = f[max(k1 - 1, 0)][j - 1];
f[i][j] = max(f[max(0, d2[i] - 1)][j] - 1, f[i][j]);
}
else{
f[i][j] = f[max(d2[i] - 1, 0)][j] - 1;
}
}
}
f0(j, p + 1) if(f[n][j] >= 0) return 1;
return 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> p >> q;
f1(i, n) cin >> a[i];
if(p + q >= n){
cout << 1; return 0;
}
sort(a + 1, a + n + 1);
int l = 1, r = 1e9 + 2, ans = -1;
while(l <= r){
int m = (l + r)/2;
if(solve(m)) r = m - 1, ans = m;
else l = m + 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |