제출 #1358077

#제출 시각아이디문제언어결과실행 시간메모리
1358077nathako9nSure Bet (CEOI17_sure)C++20
100 / 100
38 ms1924 KiB
#include<bits/stdc++.h>
#define ll long long
#define db double
using namespace std;

const int N=100005;
db A[N+3],B[N+3];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>A[i]>>B[i];
    }

    sort(A+1,A+n+1,greater<db>());
    sort(B+1,B+n+1,greater<db>());

    db sa=0.0,sb=0.0,ans=0.0;
    int pa=1,pb=1;

    for(int i=1; i<=2*n; i++){
        // CHANGE: Use a very small value to represent an invalid/impossible move
        db ca = -1e18, cb = -1e18; 
        
        // CHANGE: Correctly calculate the guaranteed profit (min outcome - total bets)
        // If we pick from A, the new profit is min(sa + A[pa], sb) - cost i
        if(pa <= n) ca = min(sa + A[pa], sb) - i;
        
        // If we pick from B, the new profit is min(sa, sb + B[pb]) - cost i
        if(pb <= n) cb = min(sa, sb + B[pb]) - i;

        // CHANGE: Added strict bounds checking (pa <= n, pb <= n) 
        // and fixed the comparison logic to ensure we always pick the better move
        if(pa <= n && (ca >= cb)){
            sa += A[pa];
            pa++;
            ans = max(ans, ca);
        }
        else if(pb <= n){
            sb += B[pb];
            pb++;
            ans = max(ans, cb);
        }
       
    }
    

    cout<<fixed<<setprecision(4)<<ans;
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…