Submission #855993

# Submission time Handle Problem Language Result Execution time Memory
855993 2023-10-02T13:45:10 Z Cyanmond Sure Bet (CEOI17_sure) C++17
100 / 100
63 ms 3664 KB
#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), '.') <= 4) s += '0';
    for (const auto e : s) {
        if (std::isdigit(e)) {
            ret = 10 * ret + (e - '0');
        } else {
            continue;
        }
    }
    return ret;
}

void out(i64 v) {
    cout << v / 10000 << '.';
    i64 m = v % 10000;
    string s = to_string(m);
    while (s.size() < 4) s += '0';
    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) * 10000ll);
    }
    out(ans);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    main_2();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 344 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
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 344 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 2392 KB Output is correct
18 Correct 56 ms 1880 KB Output is correct
19 Correct 57 ms 1880 KB Output is correct
20 Correct 57 ms 3164 KB Output is correct
21 Correct 63 ms 3664 KB Output is correct
22 Correct 56 ms 3164 KB Output is correct
23 Correct 57 ms 3152 KB Output is correct
24 Correct 60 ms 3152 KB Output is correct
25 Correct 57 ms 3384 KB Output is correct
26 Correct 60 ms 3664 KB Output is correct