Submission #468529

# Submission time Handle Problem Language Result Execution time Memory
468529 2021-08-28T16:03:49 Z Vladth11 Sure Bet (CEOI17_sure) C++14
100 / 100
165 ms 3580 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 30013;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;

double a[NMAX];
double b[NMAX];
int n;

int main() {
    int i, j;
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1);
    reverse(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    reverse(b + 1, b + n + 1);
    double maxim = 0;
    int sum = 0;
    i = 1, j = 1;
    double sa = 0, sb = 0;
    for(int bets = 1; bets <= 2 * n; bets++){
        if(sa == sb) {
            ///poate mai facem ceva modificari
            if(j > n) {
                sa += a[i];
                i++;
                continue;
            }
            if(i > n) {
                sb += b[j];
                j++;
                continue;
            }
            if(a[i] < b[j]) {
                sb += b[j];
                j++;
                continue;
            }
            sa += a[i];
            i++;
        } else if(sa < sb) {
            if(i > n) {
                sb += b[j];
                j++;
                continue;
            }
            sa += a[i];
            i++;
        } else if(sa > sb) {
            if(j > n) {
                sa += a[i];
                i++;
                continue;
            }
            sb += b[j];
            j++;
        }
        maxim = max(maxim, min(sa, sb) - bets);
    }
    cout << fixed << setprecision(4) << maxim;
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:38:9: warning: unused variable 'sum' [-Wunused-variable]
   38 |     int sum = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 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 204 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 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 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 204 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 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 146 ms 1760 KB Output is correct
18 Correct 147 ms 3260 KB Output is correct
19 Correct 149 ms 3144 KB Output is correct
20 Correct 145 ms 3184 KB Output is correct
21 Correct 165 ms 3580 KB Output is correct
22 Correct 151 ms 3136 KB Output is correct
23 Correct 145 ms 3204 KB Output is correct
24 Correct 147 ms 3188 KB Output is correct
25 Correct 148 ms 3160 KB Output is correct
26 Correct 165 ms 3524 KB Output is correct