제출 #1143529

#제출 시각아이디문제언어결과실행 시간메모리
1143529am_aadvikWatching (JOI13_watching)C++20
100 / 100
232 ms492 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; bool comp(pair<int, int> a, int v) {return a.first < v;} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, p, q; cin >> n >> p >> q; if ((p + q) >= n) { cout << 1; return 0; } vector<pair<int, int>> a(n); for (int i = 0; i < n; ++i) cin >> a[i].first; sort(a.begin(), a.end()); for (int i = 0; i < n; ++i) a[i].second = i; int s = 0, e = 1e9, ans = -1; while (s <= e) { int w = (s + e) / 2; vector<int> cur(n + 1, 1e9), prv(n + 1, 1e9); vector<vector<int>> lb(2, vector<int>(n + 1)); for (int i = 0; i < n; ++i) { auto it = lower_bound(a.begin(), a.end(), a[i].first + w, comp); lb[0][i] = (it == a.end()) ? -1 : (*it).second; it = lower_bound(a.begin(), a.end(), a[i].first + w + w, comp); lb[1][i] = (it == a.end()) ? -1 : (*it).second; } for (int cp = 0; cp <= p; ++cp) { for (int i = n - 1; i >= 0; --i) { if (cp > 0) { auto idx = lb[0][i]; if (idx == -1) cur[i] = min(cur[i], 0); else cur[i] = min(cur[i], prv[idx]); } auto idx = lb[1][i]; if (idx == -1) cur[i] = min(cur[i], 1); else cur[i] = min(cur[i], 1 + cur[idx]); } prv = cur, cur.assign(n + 1, 1e9); } if (prv[0] <= q) ans = w, e = w - 1; else s = w + 1; } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...