Submission #767706

#TimeUsernameProblemLanguageResultExecution timeMemory
767706ParsaSSure Bet (CEOI17_sure)C++17
100 / 100
83 ms6092 KiB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
const int N = 2e5 + 5;
double a[N], b[N], A[N], B[N], mx[N];
int n;

void solve() {
    cin >> 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>());
    for (int i = 1; i <= n; i++) {
        A[i] = A[i - 1] + a[i - 1] - 1;
        B[i] = B[i - 1] + b[i - 1] - 1;
        mx[i] = max(mx[i - 1], B[i]);
    }
    double l = 0, r = 1e9 + 10;
    for (int i = 0; i < 120; i++) {
        double x = (l + r) / 2.;
        bool ok = false;
        for (int j = 0; j <= n; j++) {
            int r = min((double)n, (A[j] - x));
            ok |= r >= 0 && mx[r] >= j + x;
        }
        if (ok)
            l = x;
        else
            r = x;
    }
    cout << fixed << setprecision(4) << r << '\n';
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...