Submission #653021

# Submission time Handle Problem Language Result Execution time Memory
653021 2022-10-25T12:27:55 Z pauloamed Sure Bet (CEOI17_sure) C++14
0 / 100
1 ms 212 KB
#include<bits/stdc++.h>
using namespace std;


int32_t main(){
  cin.tie(NULL)->sync_with_stdio(false);
  int n; cin >> n;
  vector<double> a, b;
  for(int i = 0; i < n; ++i){
    double x, y; cin >> x >> y;
    a.push_back(x);
    b.push_back(y);
  }

  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());

  vector<double> sa, sb;
  for(int i = 0; i < n; ++i){
    sa.push_back(a[i]);
    sb.push_back(b[i]);
    if(i){
      sa[i] += sa[i - 1];
      sb[i] += sb[i - 1];
    }
  }

  double ans = 0;
  int ai = 0, bi = 0;
  double sum_a = 0, sum_b = 0;
  int tot = 0;
  while(ai < n && bi < n){
    if(ai == n){
      tot++; sum_b = sb[bi++];
    }else if(bi == n){
      tot++; sum_a = sa[ai++];
    }else{
      tot++;
      if(sum_b < sum_a) sum_b = sb[bi++];  
      else sum_a = sa[ai++];
    }
    double cost = min(sum_a, sum_b) - tot;
    ans = max(ans, cost);
  }
  cout << setprecision(4) << fixed << ans << "\n";

}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -