Submission #653022

# Submission time Handle Problem Language Result Execution time Memory
653022 2022-10-25T12:30:30 Z ayalla Sure Bet (CEOI17_sure) C++14
100 / 100
94 ms 4412 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long int
#define endl '\n'
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100005
#define mod 1000000007

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<double> a(n);
  vector<double> b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i] >> b[i];
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  vector<double> pref(n + 1, 0);
  for (int i = 0; i < n; i++)
  {
    pref[i + 1] = pref[i] + b[i];
  }
  double ans = 0.0, luc = 0, qt = 0.0;
  for (int i = 0; i < n; i++)
  {
    luc += a[i];
    qt += 1;
    auto f = [&](int x)
    {
      return min(pref[x] - (qt + x), luc - (qt + x));
    };
    int l = 1, r = n;
    while (l < r)
    {
      int mid = (l + r) >> 1;
      (f(mid) > f(mid + 1)) ? r = mid : l = mid + 1;
    }
    ans = max(ans, f(l));
  }
  cout << fixed << setprecision(4) << ans << endl;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 87 ms 4036 KB Output is correct
18 Correct 84 ms 3916 KB Output is correct
19 Correct 85 ms 3912 KB Output is correct
20 Correct 87 ms 3912 KB Output is correct
21 Correct 89 ms 4304 KB Output is correct
22 Correct 83 ms 4040 KB Output is correct
23 Correct 84 ms 3920 KB Output is correct
24 Correct 85 ms 3920 KB Output is correct
25 Correct 84 ms 4028 KB Output is correct
26 Correct 94 ms 4412 KB Output is correct