Submission #972982

#TimeUsernameProblemLanguageResultExecution timeMemory
972982bonkWatching (JOI13_watching)C++17
100 / 100
235 ms16296 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e8; const int MAX_N = 2005; int dp[MAX_N][MAX_N], a[MAX_N], nxtP[MAX_N], nxtQ[MAX_N]; int N, P, Q; int f(int idx, int remQ){ if(remQ < 0) return INF; if(idx > N) return 0; auto &cur = dp[idx][remQ]; if(cur != -1) return cur; cur = min(f(nxtP[idx], remQ) + 1, f(nxtQ[idx], remQ - 1)); return cur; } bool check(int x){ int j = 2, k = 2; for(int i = 1; i <= N; i++){ while(j <= N && a[j] - a[i] + 1 <= x) j++; while(k <= N && a[k] - a[i] + 1 <= 2*x) k++; nxtP[i] = j; nxtQ[i] = k; } memset(dp, -1, sizeof(dp)); return (f(1, Q) <= P); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> N >> P >> Q; P = min(P, N); Q = min(Q, N); for(int i = 1; i <= N; i++) cin >> a[i]; sort(a + 1, a + N + 1); ll ans = -1, l = 1, r = 1e9; while(l <= r){ int mid = (l + r)/2; if(check(mid)){ ans = mid; r = mid - 1; } else{ l = mid + 1; } } cout << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...