Submission #498349

# Submission time Handle Problem Language Result Execution time Memory
498349 2021-12-25T04:41:10 Z kingline Sure Bet (CEOI17_sure) C++17
100 / 100
121 ms 2656 KB
/*#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include <bits/stdc++.h>
#pragma GCC optimize ("unroll-loops,Ofast,O3")
#pragma GCC target("avx,avx2,fma")
//#define file(data) freopen(data".in", "r", stdin); freopen(data".out", "w", stdout);
#define pb push_back
//#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(data) data.begin() , data.end()
#define endl '\n'
//freopen("nenokku_easy.in", "r", stdin);
//freopen("nenokku_easy.out", "w", stdout);
#define int long long
#define pii pair < int, int >
#define pll pair < long long, long long >

using namespace std;

typedef long long ll;
const int N = 2e5 + 5;
const int M = 305;
const int mod = 1e9 + 7;

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

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //file("pieaters");
    cin >> n;
    for(int 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);
    for(int i = 1; i <= n; i++) {
        pref[i] = pref[i - 1] + b[i];
    }
    double ans = 0, suma = 0;
    for(int i = 1; i <= n; i++) {
        suma += a[i];
        int l = 1, r = n;
        while(r - l > 2) {
            int md1 = l + (r - l) / 3, md2 = r - (r - l) / 3;
            if(min(suma, pref[md1]) - i - md1 >= min(suma, pref[md2]) - i - md2) {
                r = md2;
            } else {
                l = md1;
            }
        }
        ans = max(ans, min(suma - i - r, pref[r] - i - r));
        ans = max(ans, min(suma - i - l, pref[l] - i - l));
        l++;
        ans = max(ans, min(suma - i - l, pref[l] - i - l));
        /*
        for(int j = 1; j <= n; j++) {
            ans = max(ans, min(suma, pref[j]) - i - j);
        }*/
    }
    cout << fixed << setprecision(4) << ans;
}















Compilation message

sure.cpp:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 104 ms 2632 KB Output is correct
18 Correct 95 ms 2656 KB Output is correct
19 Correct 93 ms 2560 KB Output is correct
20 Correct 94 ms 2632 KB Output is correct
21 Correct 102 ms 2656 KB Output is correct
22 Correct 117 ms 2560 KB Output is correct
23 Correct 95 ms 2576 KB Output is correct
24 Correct 92 ms 2628 KB Output is correct
25 Correct 96 ms 2556 KB Output is correct
26 Correct 121 ms 2540 KB Output is correct