Submission #42962

#TimeUsernameProblemLanguageResultExecution timeMemory
42962krauchSure Bet (CEOI17_sure)C++14
100 / 100
113 ms17708 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double ld; typedef pair < int, int > PII; #define F first #define S second #define mkp make_pair #define eb emplace_back #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define y1 kekek #define left(v) v << 1 #define right(v) v << 1 | 1 #define forn(x, a, b) for (int x = a; x <= b; ++x) #define for1(x, a, b) for (int x = a; x >= b; --x) const ll ool = 1e18 + 9; const int N = 2e5 + 6, oo = 1e9 + 9, base = 1e9 + 7; int n; ld a[N], b[N], pref[N]; pair < ld, ld > mymin(pair < ld, ld > a, pair < ld, ld > b) { if (min(a.F, a.S) < min(b.F, b.S)) return b; return a; } int main() { ios_base :: sync_with_stdio(0); cin.tie(0); #ifdef krauch freopen("input.txt", "r", stdin); #endif cin >> n; forn(i, 1, n) { cin >> a[i] >> b[i]; } sort(a + 1, a + n + 1); reverse(a + 1, a + n + 1); sort(b + 1, b + n + 1); reverse(b + 1, b + n + 1); forn(i, 1, n) { pref[i] += pref[i - 1] + b[i] - 1; } ld sum = 0; pair < ld, ld > ans = mkp(0, 0); forn(i, 1, n) { sum += a[i] - 1; int l = 0, r = n; while (l < r) { int mid = (l + r) >> 1; if (pref[mid] - i >= sum - mid) r = mid; else l = mid + 1; } forn(j, max(l - 2, 0), min(l + 1, n)) { ans = mymin(ans, mkp(pref[j] - i, sum - j)); } } cout << fixed << setprecision(4) << min(ans.F, ans.S) << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...