Submission #891170

#TimeUsernameProblemLanguageResultExecution timeMemory
891170vjudge1Sure Bet (CEOI17_sure)C++17
100 / 100
89 ms4724 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define ll long long #define ull unsigned long long #define ld long double #define pf push_front #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() void boost(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); return; } void solve(){ int n; cin>>n; ld a[n],b[n]; for(int i=0; i<n; i++) cin>>a[i]>>b[i]; sort(a,a+n,greater<double>()); sort(b,b+n,greater<double>()); int p1=0,p2=0; int cnt=0; ld suma=0,sumb=0; ld ans=0; while(p1<n||p2<n){ if(p1==n||p2==n){ if(p1==n){ sumb+=b[p2]; p2++; } else{ suma+=a[p1]; p1++; } } else{ if(suma>sumb){ sumb+=b[p2]; p2++; } else{ suma+=a[p1]; p1++; } } cnt++; ans=max(ans,min(suma,sumb)-cnt); } cout<<fixed<<setprecision(4)<<ans; return; } int main(){ boost(); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...