Submission #504130

# Submission time Handle Problem Language Result Execution time Memory
504130 2022-01-09T21:59:55 Z Hacv16 Sure Bet (CEOI17_sure) C++17
100 / 100
83 ms 3448 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAX = 2e6 + 15;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

#define pb push_back
#define sz(x) (int) x.size()
#define fr first
#define sc second
#define mp make_pair
#define all(x) x.begin(), x.end()

int n;
long double a[MAX], b[MAX];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    sort(a, a + n, greater<long double>());
    sort(b, b + n, greater<long double>());

    int pa = 1, pb = 1;
    long double sa = a[0], sb = b[0], ans = max((long double) 0, min(sa - 2, sb - 2));

    while(pa != n && pb != n){
        if(sa < sb){
            sa += a[pa];
            pa++;
        }else{
            sb += b[pb];
            pb++;
        }

        ans = max(ans, min(sa - (pa + pb), sb - (pa + pb)));
    }
 
    cout << setprecision(4) << fixed << ans << '\n';

    return 0;
}

 
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?)
    * do smth instead of nothing and stay organized
    * brute force to find pattern?
    * sort?
    * graph?
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 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 332 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 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 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 332 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 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 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 77 ms 3388 KB Output is correct
18 Correct 78 ms 3448 KB Output is correct
19 Correct 79 ms 3404 KB Output is correct
20 Correct 79 ms 3392 KB Output is correct
21 Correct 83 ms 3372 KB Output is correct
22 Correct 79 ms 3400 KB Output is correct
23 Correct 77 ms 3352 KB Output is correct
24 Correct 78 ms 3324 KB Output is correct
25 Correct 80 ms 3404 KB Output is correct
26 Correct 81 ms 3328 KB Output is correct