Submission #51439

#TimeUsernameProblemLanguageResultExecution timeMemory
51439EntityITWatching (JOI13_watching)C++14
100 / 100
457 ms32252 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int N = 2005, inf = 1e18; int n, p, q, a[N], dp[N][N]; signed main () { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> q; if (p >= n || q >= n) return cout << 1, 0; for (int i = 1; i <= n; ++i) cin >> a[i]; sort (a + 1, a + n + 1); int l = 1, r = 1000000000; while (l < r) { int mid = (l + r) >> 1, pter1, pter2; pter1 = pter2 = 1; memset (dp, 63, sizeof dp); dp[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j <= p; ++j) { if (dp[i][j] >= inf) continue; while (pter1 <= n && a[pter1] <= a[i + 1] + mid - 1) pter1++; dp[pter1 - 1][j + 1] = min (dp[pter1 - 1][j + 1], dp[i][j]); while (pter2 <= n && a[pter2] <= a[i + 1] + 2 * mid - 1) pter2++; dp[pter2 - 1][j] = min (dp[pter2 - 1][j], dp[i][j] + 1); } } bool ok = 0; for (int j = 0; j <= p; ++j) { if (dp[n][j] <= q) { ok = 1; break; } } if (ok) r = mid; else l = mid + 1; } cout << l; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...