Submission #142996

#TimeUsernameProblemLanguageResultExecution timeMemory
142996MilkiSure Bet (CEOI17_sure)C++14
100 / 100
105 ms3740 KiB
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define _ << " " <<
#define sz(x) ((int) x.size())
#define pb(x) push_back(x)
#define TRACE(x) cerr << #x << " = " << x << endl

typedef long long ll;
typedef pair<int, int> point;

const int MAXN = 1e5 + 5;

int n;
double a[MAXN], b[MAXN];

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);

  cin >> n;
  REP(i, n){
    cin >> a[i] >> b[i];
  }
  sort(a, a + n, greater<double>());
  sort(b, b + n, greater<double>());

  double sol = 0;
  double lt = 0, rt = 0;
  int pnt = 0, total = 0;

  REP(i, n){
    lt += a[i];
    total ++;
    while(pnt < n && lt > rt){
      rt += b[pnt];
      pnt ++;
      total ++;
      sol = max(sol, min(lt, rt) - total);
    }
    sol = max(sol, min(lt, rt) - total);
  }
  lt = rt = pnt = total = 0;


  REP(i, n){
    rt += b[i];
    total ++;
    while(pnt < n && rt > lt){
      lt += a[pnt];
      total ++;
      pnt ++;
      sol = max(sol, min(lt, rt) - total);
    }
    sol = max(sol, min(lt, rt) - total);
  }

  cout << setprecision(4) << fixed << sol;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...