제출 #976025

#제출 시각아이디문제언어결과실행 시간메모리
976025vjudge1Watching (JOI13_watching)C++17
0 / 100
2 ms512 KiB
#include <bits/stdc++.h> #define int long long #define f first #define s second #define pb push_back #define endl '\n' using namespace std; int N,K,B,a[2005]; bool check(int x) { priority_queue<pair<int, pair<int, int>>> p; pair<int, int> cst[2005]; for (int i = 1; i <= 2003; i++) cst[i] = {-1, -1}; p.push({1, {B, K}}); while (!p.empty()) { auto cur = p.top(); p.pop(); int idx = cur.f; int ku = cur.s.s; int bu = cur.s.f; // cout << idx << ' ' << bu << ' ' << ku << endl; if (idx >= N + 1) return true; int nxt_idx = idx; if (ku > 0) { while (a[nxt_idx + 1] - a[idx] + 1 <= x && nxt_idx <= N) nxt_idx++; pair<int, int> c = {bu, ku - 1}; if (cst[nxt_idx + 1] < c) { p.push({nxt_idx + 1, c}); cst[nxt_idx + 1] = c; } } if (bu > 0) { while (a[nxt_idx + 1] - a[idx] + 1 <= 2 * x && nxt_idx <= N) nxt_idx++; pair<int, int> c = {bu - 1, ku}; if (cst[nxt_idx + 1] < c) { p.push({nxt_idx + 1, c}); cst[nxt_idx + 1] = c; } } } return false; } void solve() { cin >> N >> K >> B; for (int i = 1; i <= N; i++) cin >> a[i]; sort(a + 1, a + 1 + N); int l = 1; int r = 1e9; int ans = -1; while (l <= r) { int mid = (l + r) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } assert(ans != -1); cout << ans << endl; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int tttt = 1; // cin >> tttt; while (tttt--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...