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, a[N], p, q, f[N][N], d1[N], d2[N];
bool check(int dist){
f1(i, n){
d1[i] = lower_bound(a + 1, a + n + 1, a[i] - dist + 1) - a;
d2[i] = lower_bound(a + 1, a + n + 1, a[i] - 2*dist + 1) - a;
}
f0(i, p + 1) f[0][i] = q;
f1(i, n) f1(j, p) f[i][j] = -1e9;
/// f[i][j] den i, dung j camera thi con lai max la bao nhieu
f1(i, n){
f0(j, p + 1){
f[i][j] = f[d2[i] - 1][j] - 1;
if(j > 0){
f[i][j] = max(f[i][j], f[d1[i] - 1][j - 1]);
}
}
}
return f[n][p] >= 0;
}
int main(){
ios_base::sync_with_stdio(0);
cin >> n >> p >> q;
f1(i, n) cin >> a[i];
sort(a + 1, a + n + 1);
if(p + q >= n){
cout << 1;
return 0;
}
int l = 1, r = 1e9 + 5, ans = r;
while(l <= r){
int mid = (l + r)/2;
if(check(mid)) r = mid - 1, ans = mid;
else l = mid + 1;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |