Submission #1246119

#TimeUsernameProblemLanguageResultExecution timeMemory
1246119A_M_Namdar구경하기 (JOI13_watching)C++20
100 / 100
178 ms16252 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 10; int n, p, q, a[N]; bool check(int w) { int dp[n + 10][n + 10] = {}; memset(dp, 63, sizeof dp); dp[0][0] = 0; int p1 = 0, p2 = 0; for (int i = 0; i < n; i++) { while (p1 < n && a[p1] - a[i] < w) p1++; while (p2 < n && a[p2] - a[i] < w * 2) p2++; for (int j = 0; j < n + 10; j++) { // if (w == 3) cout << i << ' ' << j << ' ' << dp[i][j] << '\n'; dp[p1][j] = min(dp[p1][j], dp[i][j] + 1); if (j + 1 < n + 10) dp[p2][j + 1] = min(dp[p2][j + 1], dp[i][j]); } } // for (int j = 0; j < n + 10; j++) // if (w == 3) cout << n << ' ' << j << ' ' << dp[n][j] << '\n'; for (int i = 0; i <= q; i++) if (dp[n][i] <= p) return true; return false; } void input() { cin >> n >> p >> q; for (int i = 0; i < n; i++) cin >> a[i]; } void solve() { sort(a, a + n); if (p + q >= n) { cout << 1 << '\n'; return; } int l = 0, r = 1e9 + 10; while (r - l > 1) { int mid = (l + r) / 2; // cout << l << ' ' << r << ' ' << mid << endl; if (check(mid)) r = mid; else l = mid; } cout << r; } int main() { ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0); input(); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...