Submission #42962

# Submission time Handle Problem Language Result Execution time Memory
42962 2018-03-07T05:56:42 Z krauch Sure Bet (CEOI17_sure) C++14
100 / 100
113 ms 17708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double ld;
typedef pair < int, int > PII;

#define F first
#define S second
#define mkp make_pair
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekek
#define left(v) v << 1
#define right(v) v << 1 | 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)

const ll ool = 1e18 + 9;
const int N = 2e5 + 6, oo = 1e9 + 9, base = 1e9 + 7;

int n;
ld a[N], b[N], pref[N];

pair < ld, ld > mymin(pair < ld, ld > a, pair < ld, ld > b) {
    if (min(a.F, a.S) < min(b.F, b.S)) return b;
    return a;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #endif

    cin >> n;
    forn(i, 1, n) {
        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);

    forn(i, 1, n) {
        pref[i] += pref[i - 1] + b[i] - 1;
    }

    ld sum = 0;
    pair < ld, ld > ans = mkp(0, 0);
    forn(i, 1, n) {
        sum += a[i] - 1;
        int l = 0, r = n;
        while (l < r) {
            int mid = (l + r) >> 1;
            if (pref[mid] - i >= sum - mid) r = mid;
            else l = mid + 1;
        }
        forn(j, max(l - 2, 0), min(l + 1, n)) {
            ans = mymin(ans, mkp(pref[j] - i, sum - j));
        }
    }

    cout << fixed << setprecision(4) << min(ans.F, ans.S) << "\n";

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 1 ms 644 KB Output is correct
10 Correct 2 ms 668 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 3 ms 676 KB Output is correct
13 Correct 3 ms 728 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 3 ms 792 KB Output is correct
16 Correct 3 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 2 ms 592 KB Output is correct
6 Correct 2 ms 596 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 1 ms 644 KB Output is correct
10 Correct 2 ms 668 KB Output is correct
11 Correct 2 ms 672 KB Output is correct
12 Correct 3 ms 676 KB Output is correct
13 Correct 3 ms 728 KB Output is correct
14 Correct 2 ms 760 KB Output is correct
15 Correct 3 ms 792 KB Output is correct
16 Correct 3 ms 808 KB Output is correct
17 Correct 102 ms 4556 KB Output is correct
18 Correct 113 ms 5940 KB Output is correct
19 Correct 112 ms 7500 KB Output is correct
20 Correct 111 ms 8728 KB Output is correct
21 Correct 107 ms 10608 KB Output is correct
22 Correct 111 ms 11836 KB Output is correct
23 Correct 105 ms 13340 KB Output is correct
24 Correct 105 ms 14716 KB Output is correct
25 Correct 105 ms 15972 KB Output is correct
26 Correct 108 ms 17708 KB Output is correct