Submission #1174234

#TimeUsernameProblemLanguageResultExecution timeMemory
1174234nguyenkhangninh99Watching (JOI13_watching)C++17
100 / 100
121 ms16164 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2e3 + 5; int a[maxn], dp[maxn][maxn], prep[maxn], preq[maxn]; signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, p, q; cin >> n >> p >> q; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); if (n <= p + q) cout << 1; else{ int ans = 0; for (int bit = 29; bit >= 0; bit--) { int cur = ans | (1 << bit), pp = 0, pq = 0; for(int i = 1; i <= n; i++){ while(pp + 1 <= n && a[i] - a[pp + 1] >= cur) pp++; while(pq + 1 <= n && a[i] - a[pq + 1] >= 2 * cur) pq++; prep[i] = pp; preq[i] = pq; } for (int i = 1; i <= n; i++){ for (int j = 0; j <= q; j++){ dp[i][j] = dp[prep[i]][j] + 1; if(j) dp[i][j] = min(dp[i][j], dp[preq[i]][j - 1]); } } if(dp[n][q] > p) ans = cur; } cout << ans + 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...