제출 #855997

#제출 시각아이디문제언어결과실행 시간메모리
855997CyanmondSure Bet (CEOI17_sure)C++17
100 / 100
30 ms2020 KiB
#include <bits/stdc++.h>

using namespace std;

#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= l; --i)
#define ALL(x) (x).begin(), (x).end()

using i64 = long long;

i64 parse() {
    i64 ret = 0;
    string s;
    cin >> s;
    if (find(ALL(s), '.') == s.end()) s.push_back('.');
    while (s.end() - find(ALL(s), '.') <= 6) s += '0';
    for (const auto e : s) {
        if (std::isdigit(e)) {
            ret = 10 * ret + (e - '0');
        } else {
            continue;
        }
    }
    return ret;
}

void out(i64 v) {
    i64 x = v % 100;
    v /= 100;
    if (x >= 50) ++v;
    
    cout << v / 10000 << '.';
    i64 m = v % 10000;
    string s = to_string(m);
    while (s.size() < 4) s = '0' + s;
    cout << s;
    cout << endl;
}

void main_2() {
    int N;
    cin >> N;
    vector<double> A(N), B(N);
    rep(i, 0, N) cin >> A[i] >> B[i];
    sort(ALL(A), greater());
    sort(ALL(B), greater());

    long double sumA = 0, sumB = 0;
    int i = 0, j = 0;
    long double ans = 0;
    while (i < N or j < N) {
        if (sumA < sumB) {
            if (i == N) break;
            sumA += A[i];
            ++i;
        } else {
            if (j == N) break;
            sumB += B[j];
            ++j;
        }
        ans = max(ans, min(sumA, sumB) - (long double)(i + j));
    }
    cout << fixed << setprecision(4) << ans << endl;
}

void main_() {
    int N;
    cin >> N;
    vector<i64> A(N), B(N);
    rep(i, 0, N) {
        A[i] = parse();
        B[i] = parse();
    }
    sort(ALL(A), greater());
    sort(ALL(B), greater());

    i64 sumA = 0, sumB = 0;
    int i = 0, j = 0;
    i64 ans = 0;
    while (i < N or j < N) {
        if (sumA < sumB) {
            if (i == N) break;
            sumA += A[i];
            ++i;
        } else {
            if (j == N) break;
            sumB += B[j];
            ++j;
        }
        ans = max(ans, min(sumA, sumB) - (i + j) * 1000000ll);
    }
    out(ans);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    main_();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...