Submission #865230

# Submission time Handle Problem Language Result Execution time Memory
865230 2023-10-24T06:41:25 Z vjudge1 Sure Bet (CEOI17_sure) C++17
100 / 100
77 ms 6796 KB
// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define int long long
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define F first
#define S second
#define md (tl+tr)/2
#define TL v+v,tl,mid
#define TR v+v+1,mid+1,tr

#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

using namespace std;

int binpow(int a,int n,int M) {
    if (n==0)
        return 1;
    if (n%2!=0)
        return (a * binpow(a,n-1,M))%M;
    int z=binpow(a,n/2,M);
    return (z*z)%M;
}

const ll INF = 1e18;
const int N =  1e6+7;
const int M = 1e9+7;
const ll HZ = 1e5;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const db pi = 3.141592653;
const int P=31;

int n;
db a[N],b[N],ans;

void solve() {
    cin >> n;
    for (int i=1;i<=n;i++)
        cin >> a[i] >> b[i];
    sort (a+1,a+n+1), sort (b+1,b+n+1);
    int i=n,j=n,cnt=0;
    db sum1=0,sum2=0;
    while (i>0 or j>0) {
        while (i>0 and (sum1<=sum2 or j==0)) {
            sum1+=a[i];
            i--, cnt++;
            ans=max(ans,min(sum1,sum2)-cnt);
        }
        while (j>0 and (sum2<=sum1 or i==0)) {
            sum2+=b[j];
            j--, cnt++;
            ans=max(ans,min(sum1,sum2)-cnt);
        }
    }
    printf("%.4lf",(double)ans);
}

signed main() {
    // freopen("lca.in", "r", stdin);
    // freopen("lca.out", "w", stdout);
    kanagattandirilmagandiktarinizdan
    int test = 1, count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ":\n";
        solve();
        if (test)
            // cout << '\n';
            count++;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2440 KB Output is correct
8 Correct 0 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2440 KB Output is correct
8 Correct 0 ms 2648 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 77 ms 6736 KB Output is correct
18 Correct 57 ms 6772 KB Output is correct
19 Correct 64 ms 6788 KB Output is correct
20 Correct 57 ms 6792 KB Output is correct
21 Correct 59 ms 6772 KB Output is correct
22 Correct 65 ms 6740 KB Output is correct
23 Correct 56 ms 6740 KB Output is correct
24 Correct 69 ms 6740 KB Output is correct
25 Correct 62 ms 6740 KB Output is correct
26 Correct 70 ms 6796 KB Output is correct