Submission #550838

#TimeUsernameProblemLanguageResultExecution timeMemory
550838Soumya1Watching (JOI13_watching)C++17
100 / 100
983 ms16528 KiB
#include <bits/stdc++.h> #ifdef __LOCAL__ #include <debug_local.h> #endif using namespace std; void testCase() { int n, p, q; cin >> n >> p >> q; p = min(p, n + 50); q = min(q, n + 50); vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i]; sort(a.begin(), a.end()); auto check = [&](int w) { vector<vector<int>> dp(n + 1, vector<int> (p + 1, q + 1)); vector<int> to(n + 1), to1(n + 1); for (int i = 1; i <= n; i++) { to[i] = lower_bound(a.begin(), a.end(), a[i] - w + 1) - a.begin() - 1; to1[i] = lower_bound(a.begin(), a.end(), a[i] - 2 * w + 1) - a.begin() - 1; to[i] = max(0, to[i]); to1[i] = max(0, to1[i]); } dp[0] = vector<int> (p + 1, 0); for (int i = 1; i <= n; i++) { for (int j = 0; j <= p; j++) { if (j) dp[i][j] = dp[to[i]][j - 1]; if (dp[to1[i]][j] < q) dp[i][j] = min(dp[i][j], dp[to1[i]][j] + 1); } } return (*min_element(dp[n].begin(), dp[n].end()) <= q); }; int lo = 1, hi = 1e9; while (lo < hi) { int mid = (lo + hi) >> 1; if (check(mid)) hi = mid; else lo = mid + 1; } cout << lo << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); testCase(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...