Submission #637915

#TimeUsernameProblemLanguageResultExecution timeMemory
637915tvladm2009Watching (JOI13_watching)C++14
100 / 100
130 ms16016 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MAX_N = 2 * 1e3; int a[MAX_N + 1]; int dp[MAX_N + 1][MAX_N + 1]; int n, p, q; bool check(int guess) { memset(dp, 0, sizeof(dp)); int j = 1, k = 1; for (int i = 1; i <= n; i++) { while (a[i] - a[j] >= guess) { j++; } while (a[i] - a[k] >= 2 * guess) { k++; } for (int l = 0; l <= min(i, p); l++) { dp[i][l] = dp[k - 1][l] + 1; if (l != 0) { dp[i][l] = min(dp[i][l], dp[j - 1][l - 1]); } } } return (dp[n][min(n, p)] <= q); } int cb() { int l = 1, r = 1e9, sol = -1; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { sol = mid; r = mid - 1; } else { l = mid + 1; } } return sol; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> p >> q; for (int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); int ans = cb(); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...