Submission #85556

#TimeUsernameProblemLanguageResultExecution timeMemory
85556KCSCWatching (JOI13_watching)C++14
100 / 100
250 ms14872 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...