Submission #938324

#TimeUsernameProblemLanguageResultExecution timeMemory
938324vjudge1Sure Bet (CEOI17_sure)C++17
100 / 100
146 ms8104 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define ar array #define pb push_back #define ln '\n' #define int long long using i64 = long long; template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; using ld = long double; vector <ld> a, b; for ( int i = 0; i < n; i++ ){ ld x, y; cin >> x >> y; a.pb(x), b.pb(y); } sort(all(a), greater <ld> ()); sort(all(b), greater <ld> ()); n = a.size(); int m = b.size(); vector <ld> pf(m + 1), mx(m + 1); for ( int i = 0; i < m; i++ ){ pf[i + 1] = pf[i] + b[i]; mx[i + 1] = max(mx[i], pf[i + 1] - (i + 1)); } auto ok = [&](ld x){ ld s = 0; for ( int i = 0; i <= n; i++ ){ if ( s - i >= x ){ int j = max(0LL, (int)floor(s - x - i)); chmin(j, m); if ( mx[j] - i >= x ){ return true; } } if ( i < n ){ s += a[i]; } } return false; }; ld l = 0, r = 1e12; for ( int _ = 0; _ <= 100; _++ ){ ld md = (l + r) / 2; if ( ok(md) ) l = md; else r = md; } cout << fixed << setprecision(4) << l; cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...