Submission #927931

#TimeUsernameProblemLanguageResultExecution timeMemory
927931TAhmed33Sure Bet (CEOI17_sure)C++98
100 / 100
134 ms6740 KiB
#include <bits/stdc++.h> using namespace std; typedef long double ld; int n; ld a[100001]; ld b[100001]; ld pref[100001]; int main () { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); reverse(a + 1, a + n + 1); reverse(b + 1, b + n + 1); ld mx = 0; for (int i = 2; i <= n; i++) { a[i] += a[i - 1]; b[i] += b[i - 1]; } pref[1] = a[1] - 1; for (int i = 2; i <= n; i++) { pref[i] = max(pref[i - 1], a[i] - i); } for (int i = 1; i <= n; i++) { int l = 1, r = n, ans = -1; while (l <= r) { int mid = (l + r) >> 1; if (a[mid] < b[i]) { l = mid + 1; } else { r = mid - 1; ans = mid; } } if (ans != -1) { mx = max(mx, b[i] - i - ans); if (ans != -1) mx = max(mx, pref[ans - 1] - i); } else { mx = max(mx, pref[n] - i); } } cout << fixed << setprecision(4) << mx << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...