Submission #468670

# Submission time Handle Problem Language Result Execution time Memory
468670 2021-08-29T09:44:28 Z paga2004 Sure Bet (CEOI17_sure) C++14
100 / 100
99 ms 4716 KB
#include <bits/stdc++.h>

#define int long long

using namespace std;

#ifdef LOCAL
#define dbg(x) cerr << x << "\n";
#else
#define dbg(x)
#endif

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<double> a(n), b(n), prefixa(n), prefixb(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());

  prefixa[0] = a[0];
  prefixb[0] = b[0];

  for (int i = 1; i < n; i++) {
    prefixa[i] = prefixa[i - 1] + a[i];
    prefixb[i] = prefixb[i - 1] + b[i];
  }

  double best = 0;

  int pa = 0;
  int pb = 0;
  while (pa < n && pb < n) {
    double profita = prefixa[pa] - pa - pb - 2;
    double profitb = prefixb[pb] - pa - pb - 2;
    dbg(profita);
    dbg(profitb);
    best = max(min(profita, profitb), best);
    if (profita < profitb) {
      pa++;
    } else {
      pb++;
    }
  }
  printf("%.4lf\n", (double)best);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 2 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 90 ms 4716 KB Output is correct
18 Correct 88 ms 4080 KB Output is correct
19 Correct 90 ms 4196 KB Output is correct
20 Correct 99 ms 4164 KB Output is correct
21 Correct 95 ms 4192 KB Output is correct
22 Correct 88 ms 4088 KB Output is correct
23 Correct 93 ms 4164 KB Output is correct
24 Correct 88 ms 4076 KB Output is correct
25 Correct 90 ms 4084 KB Output is correct
26 Correct 97 ms 4172 KB Output is correct