Submission #485124

# Submission time Handle Problem Language Result Execution time Memory
485124 2021-11-06T08:42:18 Z bagd Sure Bet (CEOI17_sure) C++14
100 / 100
170 ms 3488 KB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    double A[N+1], B[N+1];
    for(int i=1; i<=N; i++) cin >> A[i] >> B[i];
    sort(A+1, A+N+1);
    sort(B+1, B+N+1);
    int pta = N, ptb = N;
    double suma = 0, sumb = 0;
    double ans = 0;
    int cnt = 0;
    while(pta || ptb) {
        cnt++;
        if(suma > sumb) {
            if(ptb == 0) break;
            sumb += B[ptb--];
        }
        else if(suma < sumb) {
            if(pta == 0) break;
            suma += A[pta--];
        }
        else {
            if(pta == 0) sumb += B[ptb--];
            else if(ptb == 0) suma += A[pta--];
            else if(A[pta] > B[ptb]) suma += A[pta--];
            else sumb += B[ptb--];
        }
        ans = max(ans, min(suma, sumb) - cnt);
    }
    cout << fixed << setprecision(4) << ans << "\n";
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 296 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 2 ms 204 KB Output is correct
13 Correct 2 ms 204 KB Output is correct
14 Correct 2 ms 204 KB Output is correct
15 Correct 2 ms 312 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 122 ms 3096 KB Output is correct
18 Correct 123 ms 3096 KB Output is correct
19 Correct 118 ms 3092 KB Output is correct
20 Correct 120 ms 3220 KB Output is correct
21 Correct 170 ms 3488 KB Output is correct
22 Correct 122 ms 3092 KB Output is correct
23 Correct 117 ms 3108 KB Output is correct
24 Correct 118 ms 3196 KB Output is correct
25 Correct 129 ms 3104 KB Output is correct
26 Correct 144 ms 3472 KB Output is correct