Submission #1070880

# Submission time Handle Problem Language Result Execution time Memory
1070880 2024-08-22T20:18:43 Z DeathIsAwe Sure Bet (CEOI17_sure) C++17
100 / 100
133 ms 6740 KB
#include<bits/stdc++.h>
using namespace std;


int main() {
    int n; cin >> n;
    vector<double> fb(n), sb(n), ans(2*n + 1), fp(n + 1), sp(n + 1);
    for (int i=0;i<n;i++) {
        cin >> fb[i] >> sb[i];
    }
    sort(fb.begin(), fb.end(), greater<double>());
    sort(sb.begin(), sb.end(), greater<double>());
    double dum = 0, dummer = 0;
    fp[0] = 0; sp[0] = 0;
    for (int i=0;i<n;i++) {
        dum += fb[i]; fp[i + 1] = dum;
        dummer += sb[i]; sp[i + 1] = dummer;
    }


    ans[0] = 0;
    int top, bottom, middle;
    double negdif, posdif;
    for (int i=1;i<2*n + 1;i++) {
        top = min(i, n); bottom = max(0, i - n);
        if (fp[top] - sp[bottom] <= 0) {
            ans[i] = min(fp[top] - i, sp[bottom] - i);
            continue;
        }
        if (sp[top] - fp[bottom] <= 0) {
            ans[i] = min(sp[top] - i, fp[bottom] - i);
            continue;
        }
        negdif = -10000000000000; posdif = 10000000000000;
        while (top > bottom + 1) {
            middle = (top + bottom) / 2;
            if (fp[middle] - sp[i - middle] < 0) {
                if (fp[middle] - sp[i - middle] > negdif) {
                    negdif = fp[middle] - sp[i - middle];
                }
                bottom = middle;
            } else {
                if (fp[middle] - sp[i - middle] < posdif) {
                    posdif = fp[middle] - sp[i - middle];
                }
                top = middle;
            }
        }
        ans[i] = max(min(fp[top] - i, sp[i - top] - i), min(fp[bottom] - i, sp[i - bottom] - i));
    }

    cout << fixed << setprecision(4);
    cout << *max_element(ans.begin(), ans.end());
}
# 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 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 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 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 2 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 344 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 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
12 Correct 1 ms 444 KB Output is correct
13 Correct 2 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 344 KB Output is correct
17 Correct 77 ms 6504 KB Output is correct
18 Correct 89 ms 6268 KB Output is correct
19 Correct 77 ms 6480 KB Output is correct
20 Correct 85 ms 6480 KB Output is correct
21 Correct 89 ms 6736 KB Output is correct
22 Correct 133 ms 6480 KB Output is correct
23 Correct 79 ms 6396 KB Output is correct
24 Correct 78 ms 6480 KB Output is correct
25 Correct 79 ms 6276 KB Output is correct
26 Correct 86 ms 6740 KB Output is correct