Submission #537927

#TimeUsernameProblemLanguageResultExecution timeMemory
537927theysoldtheworldSure Bet (CEOI17_sure)C++14
100 / 100
105 ms5804 KiB
#include <bits/stdc++.h> using namespace std; double Get(vector<double> a , vector<double> b) { int n = (int)a.size(); double h = 0; double ans = 0; vector<double> pref(n); for (int i = 0 ; i < n ; i++) { pref[i] = (i > 0 ? pref[i - 1] : 0) + b[i]; } auto F = [&](int mid , int i) { return min(h - (mid + 1) , pref[mid] - (i + 1)); }; int last_pos = -1; for (int i = 0 ; i < n ; i++) { h += a[i]; int l = -1 , r = n; while (r - l > 1) { int mid = l + (r - l) / 2; if (F(mid , i) > F(mid + 1 , i)) { r = mid; } else { l = mid; } } assert(l + 1 >= last_pos); last_pos = l + 1; ans = max(ans , F(l + 1 , i)); } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<double> a(n) , b(n); for (int i = 0 ; i < n ; i++) { cin >> a[i] >> b[i]; a[i] -= 1; b[i] -= 1; } sort(a.rbegin() , a.rend()); sort(b.rbegin() , b.rend()); double ans = max(Get(a , b) , Get(b , a)); cout << fixed << setprecision(4) << ans << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...