답안 #1034193

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1034193 2024-07-25T10:29:03 Z MarwenElarbi Sure Bet (CEOI17_sure) C++17
100 / 100
56 ms 3752 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int nax=1e5+5;
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    optimise;
    int n;
    cin>>n;
    vector<double> a(n),b(n);
    for (int i = 0; i < n; ++i)
    {
        cin>>a[i];
        cin>>b[i];
    }
    sort(b.rbegin(),b.rend());
    sort(a.rbegin(),a.rend());
    pair<double,double> cnt={0,0};
    double ans=0;
    int j=0;
    for (int i = 0; i < n; ++i)
    {  
        cnt.fi+=a[i];
        while(cnt.se<cnt.fi&&j<n){
            ans=max(ans,min(cnt.fi,cnt.se)-(j+i+1));
            cnt.se+=b[j];
            ans=max(ans,min(cnt.fi,cnt.se)-(j+i+2));
            j++;
        }
        ans=max(ans,min(cnt.fi,cnt.se)-(j+i+1));
    }
    while(j<n){
        ans=max(ans,min(cnt.fi,cnt.se)-(j+n));
        cnt.se+=b[j];
        ans=max(ans,min(cnt.fi,cnt.se)-(j+n+1));
        j++;
    }
    cnt={0,0};
    j=0;
    for (int i = 0; i < n; ++i)
    {  
        while(cnt.se<=cnt.fi&&j<n){
            ans=max(ans,min(cnt.fi,cnt.se)-(j+i+1));
            cnt.se+=b[j];
            ans=max(ans,min(cnt.fi,cnt.se)-(j+i+2));
            j++;
        }
        cnt.fi+=a[i];
        ans=max(ans,min(cnt.fi,cnt.se)-(j+i+1));
    }
    while(j<n){
        ans=max(ans,min(cnt.fi,cnt.se)-(j+n));
        cnt.se+=b[j];
        ans=max(ans,min(cnt.fi,cnt.se)-(j+n+1));
        j++;
    }
    cout <<fixed<<setprecision(4)<<ans<<endl;
}

        
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 56 ms 3152 KB Output is correct
18 Correct 52 ms 3164 KB Output is correct
19 Correct 48 ms 3152 KB Output is correct
20 Correct 51 ms 3152 KB Output is correct
21 Correct 55 ms 3664 KB Output is correct
22 Correct 48 ms 3384 KB Output is correct
23 Correct 48 ms 3384 KB Output is correct
24 Correct 48 ms 3160 KB Output is correct
25 Correct 49 ms 3172 KB Output is correct
26 Correct 50 ms 3752 KB Output is correct