Submission #1191223

#TimeUsernameProblemLanguageResultExecution timeMemory
1191223loomSure Bet (CEOI17_sure)C++20
100 / 100
44 ms1864 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define inf 5e18
#define nl '\n'

inline void solve(){
   int n;
   cin>>n;
   double 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 j = 0;
   double sa = 0, sb = 0, ans = 0;
   for(int i=0; i<n; i++){
      sa += a[i] - 1.0;
      sb -= 1.0;

      while(j < n and sb+b[j] < sa){
         sb += b[j] - 1.0;
         sa -= 1.0;
         j++;
      }

      ans = max(ans, sb);
      if(j < n) ans = max(ans, sa - 1.0);
   }

   cout<<fixed<<setprecision(4)<<ans;
}

signed main(){
   ios_base::sync_with_stdio(0);
   cin.tie(NULL);cout.tie(NULL);

   int t = 1;
   //cin>>t;
   while(t--) solve();

   return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...