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 DIM = 2005;
int pos[DIM], pos1[DIM], pos2[DIM], dp[DIM][DIM];
int main(void) {
#ifdef HOME
freopen("watching.in", "r", stdin);
freopen("watching.out", "w", stdout);
#endif
int n, p, q; cin >> n >> p >> q;
for (int i = 1; i <= n; ++i) {
cin >> pos[i]; }
sort(pos + 1, pos + n + 1);
int le = 1, ri = 1000000000;
while (le <= ri) {
int md = (le + ri) / 2;
for (int i = 1; i <= n; ++i) {
pos1[i] = pos2[i] = 0;
for (int j = 1; j < i; ++j) {
if (pos[i] - md >= pos[j]) {
pos1[i] = j; }
if (pos[i] - md * 2 >= pos[j]) {
pos2[i] = j; } }
for (int j = 0; j <= i; ++j) {
dp[i][j] = dp[pos2[i]][j] + 1;
if (j > 0) {
dp[i][j] = min(dp[i][j], dp[pos1[i]][j - 1]); } } }
int ans = 1000000000;
for (int i = 0; i <= min(p, n); ++i) {
ans = min(ans, dp[n][i]); }
if (ans <= q) {
ri = md - 1; }
else {
le = md + 1; } }
cout << le;
return 0; }
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |