제출 #1349305

#제출 시각아이디문제언어결과실행 시간메모리
1349305khanhphucscratchSure Bet (CEOI17_sure)C++20
20 / 100
1 ms344 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int to_number(string s)
{
    bool ok = 0;
    for(char i : s) if(i == '.') ok = 1;
    if(ok == 0) s += ".";
    while(s.size() < 5 || s[s.size()-5] != '.') s += "0";
    for(int i = 0; i < s.size(); i++) if(s[i] == '.'){
        s.erase(s.begin()+i); break;
    }
    int num = 0;
    for(char i : s) num = num * 10 + i - '0';
    return num;
}
string num_to_string(int num)
{
    string ans = to_string(num);
    while(ans.size() < 5) ans = "0" + ans;
    ans.insert(ans.end()-4, '.');
    return ans;
}
signed main()
{
    int n; cin>>n;
    vector<int> a, b;
    for(int i = 1; i <= n; i++){
        string x, y; cin>>x>>y;
        a.push_back(to_number(x)); b.push_back(to_number(y));
    }
    sort(a.begin(), a.end()); sort(b.begin(), b.end());
    int ans = 0, x = 0, y = 0;
    if(a.back() > b.back()) swap(a, b);
    for(int i = 1; i <= 2*n; i++){
        if(x < y && a.size() > 0){
            x += a.back(); a.pop_back();
        }
        else{
            y += b.back(); b.pop_back();
        }
        ans = max(ans, min(x, y) - i*10000);
    }
    cout<<num_to_string(ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...