Submission #1261963

#TimeUsernameProblemLanguageResultExecution timeMemory
1261963new_accSure Bet (CEOI17_sure)C++20
0 / 100
0 ms320 KiB
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#define allr(a) (a).rbegin(), (a).rend()
#define pb push_back
#define S second
#define F first
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF (ll)1e18
#define int ll
#define pld pair<ld,ld>

void solve() {

    int n; cin >> n;
    vector<ld> a(n),b(n);
    for (int i= 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    sort(allr(a));
    sort(allr(b));
    ld ans = 0;
    int p1 = 1, p2 = 1;
    ld cur = a[0] + b[0];
    ld Aw = a[0], Bw = b[0];
    ld cost = 2;
    ans = min(Aw - cost, Bw - cost);
    while(p1 < n && p2 < n){
        while(p1 < n && Aw < Bw){
            Aw += a[p1++]; cost++;
            ans = max(ans, min(Aw - cost, Bw - cost));
        }
        while(p2 < n && Bw <= Aw){
            Bw += b[p2++]; cost++;
            ans = max(ans, min(Aw - cost, Bw - cost));
        }
    }
    cout << ans << '\n';

}

signed main() {

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cout << fixed << setprecision(4);

    int t = 1;
    //cin >> t;
    while (t--)
        solve();

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...