Submission #1139966

#TimeUsernameProblemLanguageResultExecution timeMemory
1139966jackofall718Watching (JOI13_watching)C++20
0 / 100
0 ms648 KiB
#include <bits/stdc++.h> #include <chrono> #define ll long long int #define endl '\n' #define vn vector<ll> #define vi vector<pair <ll,ll>> using namespace std; using namespace std::chrono; const int MAX_N = 1e9 + 7; #define pii pair<ll,ll> const ll INF = 0x3f3f3f3f3f3f3f3f; #define pb push_back #define srt(vp) sort(vp.begin(), vp.end()) bool canCover(ll w, const vn &v, int p, int q) { int n = v.size(); p = min(p, n); q = min(q, n); vector<vector<int>> dp(p+1, vector<int>(q+1, -1)); dp[0][0] = 0; for (int i = 0; i <= p; i++) { for (int j = 0; j <= q; j++) { if (dp[i][j] == -1) continue; int curr = dp[i][j]; if (curr >= n) return true; if (i < p) { int k = upper_bound(v.begin(), v.end(), v[curr] + w) - v.begin() - 1; dp[i+1][j] = max(dp[i+1][j], k + 1); } if (j < q) { int k = upper_bound(v.begin(), v.end(), v[curr] + 2 * w) - v.begin() - 1; dp[i][j+1] = max(dp[i][j+1], k + 1); } } } return dp[p][q] >= n; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, p, q; cin >> n >> p >> q; vn v(n); for (ll &x : v) cin >> x; sort(v.begin(), v.end()); ll lo = 1, ho = v[n-1] - v[0]; while (lo <= ho) { ll mid = (lo + ho) / 2; if (canCover(mid, v, p, q)) { ho = mid - 1; } else { lo = mid + 1; } } cout << lo << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...