답안 #490983

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
490983 2021-11-30T02:48:22 Z kawaii Sure Bet (CEOI17_sure) C++14
0 / 100
0 ms 332 KB
#include <bits/stdc++.h>
using namespace std; 
 
int n;
long double a[100005], b[100005]; 

void solve(){  
    long double ans = 0;
    multiset<pair<long double, long double> > ms1, ms2;
    for(int i = 1; i <= n; i++){
        ms1.insert(make_pair(a[i], b[i]));
        ms2.insert(make_pair(b[i], a[i]));
    } 
    long double sum1 = 0, sum2 = 0;
    bool check = 0;
    for(int i = 1; i <= n; i++){ 
        if(sum1 <= sum2){
            pair<long double, long double> x = *ms1.rbegin(); 
            sum1 += x.first;
            ms1.erase(ms1.find(x));
            swap(x.first, x.second);
            ms2.erase(ms2.find(x));
        }
        else{
            pair<long double, long double> x = *ms2.rbegin();
            sum2 += x.first;
            ms2.erase(ms2.find(x));
            swap(x.first, x.second);
            ms1.erase(ms1.find(x));
        } 
        ans = max(ans, min(sum1, sum2) - i);
    }
    cout << ans << "\n";
}
 
signed main(){  
    ios_base::sync_with_stdio(NULL); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i]; 
    solve();
}

Compilation message

sure.cpp: In function 'void solve()':
sure.cpp:15:10: warning: unused variable 'check' [-Wunused-variable]
   15 |     bool check = 0;
      |          ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -