Submission #462035

#TimeUsernameProblemLanguageResultExecution timeMemory
462035nickyrioWatching (JOI13_watching)C++17
0 / 100
9 ms8356 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2020; int n, p, q, a[N]; int dp[N][N]; void Min(int &a, int b) { a = (a > b ? b : a); } bool Check(int w) { for (int i = 0; i <= n; ++i) { for (int j = 0; j <= p; ++j) dp[i][j] = max(0, i - j); } for (int i = 0; i < n; ++i) { int nxt_p = lower_bound(a, a + n, a[i] + w) - a; int nxt_q = lower_bound(a, a + n, a[i] + w + w) - a; for (int np = 0; np <= p; ++np) { Min(dp[nxt_p][np + 1], dp[i][np]); Min(dp[nxt_q][np], dp[i][np] + 1); } } return dp[n][p] <= q; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n >> p >> q; p = min(p, n), q = min(q, n); for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n); int l = 0, r = 1e9, cur = -1; while (l <= r) { int mid = (l + r) >> 1; if (Check(mid)) { cur = mid; r = mid - 1; } else l = mid + 1; } cout << cur << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...