Submission #545671

# Submission time Handle Problem Language Result Execution time Memory
545671 2022-04-05T06:59:05 Z Ai7081 Sure Bet (CEOI17_sure) C++17
100 / 100
86 ms 5168 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 100005;

int n;
double a[N], b[N], suma[N], sumb[N], out;

int main() {
    scanf(" %d", &n);
    for (int i=1; i<=n; i++) scanf(" %lf %lf", &a[i], &b[i]);
    sort(a+1, a+n+1, greater<double>()), sort(b+1, b+n+1, greater<double>());
    for (int i=1; i<=n; i++) suma[i] = suma[i-1] + a[i], sumb[i] = sumb[i-1] + b[i];
//    printf("suma : ");
//    for (int i=0; i<=n; i++) printf("%lf ", suma[i]);
//    printf("\nsumb : ");
//    for (int i=0; i<=n; i++) printf("%lf ", sumb[i]);
//    printf("\n");
    for (int k=2; k<=2*n; k++) {
        int l = max(1, k-n), r = min(n, k-1);
        //printf("%d %d %d : ", k, l, r);
        while (l < r) {
            int mid = (l+r)/2;
            if (suma[mid] < sumb[k-mid]) l = mid+1;
            else r = mid;
        }
        //printf("%d %.4lf %.4lf ans %.4lf\n", l, suma[l-1], sumb[k-l], max(suma[l-1], sumb[k-l]) - k);
        if (l == min(n, k-1) && suma[l] < sumb[k-l]) out = max(out, suma[l] - k);
        else if (l == max(1, k-n) && suma[l] >= sumb[k-l]) out = max(out, sumb[k-l] - k);
        else out = max(out, max(suma[l-1], sumb[k-l]) - k);
    }
    printf("%.4lf", out);
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf(" %d", &n);
      |     ~~~~~^~~~~~~~~~~
sure.cpp:11:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     for (int i=1; i<=n; i++) scanf(" %lf %lf", &a[i], &b[i]);
      |                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 67 ms 4744 KB Output is correct
18 Correct 67 ms 4784 KB Output is correct
19 Correct 69 ms 4712 KB Output is correct
20 Correct 86 ms 4684 KB Output is correct
21 Correct 69 ms 5168 KB Output is correct
22 Correct 66 ms 4684 KB Output is correct
23 Correct 68 ms 4684 KB Output is correct
24 Correct 65 ms 4736 KB Output is correct
25 Correct 68 ms 4780 KB Output is correct
26 Correct 74 ms 5124 KB Output is correct