Submission #80449

#TimeUsernameProblemLanguageResultExecution timeMemory
80449shoemakerjoSure Bet (CEOI17_sure)C++14
0 / 100
2 ms704 KiB
#include <bits/stdc++.h> using namespace std; #define double long double #define maxn 100010 int n; vector<double> a, b; double apref[maxn]; double bpref[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; double ca, cb; for (int i = 1; i <= n; i++) { cin >> ca >> cb; a.push_back(ca); b.push_back(cb); } sort(a.begin(), a.end()); sort(b.begin(), b.end()); reverse(a.begin(), a.end()); reverse(b.begin(), b.end()); double ans = 0; for (int i = 1; i <= n; i++) { apref[i] = apref[i-1] + a[i-1]; bpref[i] = bpref[i-1] + b[i-1]; } for (int i = 1; i <= n; i++) { double aprof = apref[i] - i; int lo = 1; int hi = n; //binary search to find first index such that b profit is greater than a profit if (bpref[n] - i - n < aprof - n) { ans = max(ans, bpref[n] - i - n); continue; } while (lo < hi) { int mid = (lo + hi)/2; if (bpref[mid] - i - mid < aprof - mid) { //did not go far enough lo = mid+1; } else hi = mid; } ans = max(ans, bpref[lo-1] - lo-1 - i); ans = max(ans, aprof - lo); } cout << fixed << setprecision(4); cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...