Submission #1015800

#TimeUsernameProblemLanguageResultExecution timeMemory
1015800vjudge1Sure Bet (CEOI17_sure)C++17
100 / 100
81 ms3736 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main(){ int n; cin>>n; vector<double> a(n),b(n); for (int i=0; i<n; i++) cin>>a[i]>>b[i]; sort(a.begin(),a.end(),greater<double>()); sort(b.begin(),b.end(),greater<double>()); //now take prefix sums for (int i=1; i<n; i++){ a[i]=a[i-1]+a[i]; } for (int i=1; i<n; i++){ b[i]=b[i-1]+b[i]; } double ans=0; int r=0; for (int i=0; i<n; i++){ while (r<n and b[r]<a[i]) r++; if (r>=n) break; ans=max(ans, a[i]-(i+1+r+1)); } r=0; for (int i=0; i<n; i++){ while (r<n and a[r]<b[i]) r++; if (r>=n) break; ans=max(ans, b[i]-(i+1+r+1)); } printf("%.4lf",(double)ans); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...