Submission #812677

#TimeUsernameProblemLanguageResultExecution timeMemory
812677CookieSure Bet (CEOI17_sure)C++14
100 / 100
94 ms8336 KiB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
//ifstream fin("FEEDING.INP");
//ofstream fout("FEEDING.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const int base = 74;
const ll mod = 1e9 + 7, inf = 1e9, mxv = 1005, mxn = 2e5 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
ld a[mxn + 1], b[mxn + 1], pa[mxn + 1], pb[mxn + 1];
ld val(int x, int y){
    return(min(pa[x], pb[y]) - (x + y));
}
signed main()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    ld ans = 0;
    sort(a + 1, a + n + 1, greater<ld>()); sort(b + 1, b + n + 1, greater<ld>());
    for(int i = 1; i <= n; i++){
        pa[i] = pa[i - 1] + a[i]; pb[i] = pb[i - 1] + b[i];
    }
    int l = 1, r = 1;
    ans = max(ans, min(pa[1], pb[1]) - (1 + 1));
    while(l != n|| r != n){
        if(l == n)r++;
        else if(r == n)l++;
        else if(pa[l] < pb[r])l++;
        else r++;
        ans = max(ans, min(pa[l], pb[r]) - (l + r));
        //cout << l << " " << r << " ";
    }
    cout << fixed << setprecision(4) << ans;
    return(0);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...