Submission #239311

# Submission time Handle Problem Language Result Execution time Memory
239311 2020-06-15T10:59:21 Z aggu_01000101 Sure Bet (CEOI17_sure) C++14
100 / 100
206 ms 3704 KB
#include <bits/stdc++.h>
#define int long long
#define INF 1000000000000000
#define lchild(i) (i*2 + 1)
#define rchild(i) (i*2 + 2)
#define mid(l, u) ((l+u)/2)
#define x(p) p.first
#define y(p) p.second
#define MOD 998244353
using namespace std;
bool cmp(pair<pair<double, double>, int> a, pair<pair<double, double>, int> b){
    if(a.first.first < b.first.first) return true;
    if(b.first.first < a.first.first) return false;
    if(a.first.second > b.first.second) return true;
    return false;
}
signed main(){
    int n;
    cin>>n;
    double a[2][n];
    for(int i = 0;i<n;i++) cin>>a[0][i]>>a[1][i];
    sort(a[0], a[0]+n);
    sort(a[1], a[1]+n);
    if(a[0][n-1]<=2 && a[1][n-1]<=2){
        cout<<"0\n";
        return 0;
    }
    int ind[] = {n-1, n-1};
    vector<pair<pair<double, double>, int>> pq;
    double ans = 0;
    int inv = 0;
    pq.push_back({{0, a[0][n-1]}, 0});
    pq.push_back({{0, a[1][n-1]}, 1});
    sort(pq.begin(), pq.end(), cmp);
    while(ind[pq[0].second] >= 0){
        pair<pair<double, double>, int> curr = pq[0];
        curr.first.first += a[curr.second][ind[curr.second]--];
        inv++;
        if(ind[curr.second]>=0) curr.first.second = a[curr.second][ind[curr.second]];
        else curr.first.second = -INF;
        pq[0] = curr;
        sort(pq.begin(), pq.end(), cmp);
        ans = max(ans, pq[0].first.first - inv);
    }
    printf("%.4lf",(double)ans);

}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 5 ms 256 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 6 ms 384 KB Output is correct
15 Correct 6 ms 384 KB Output is correct
16 Correct 6 ms 384 KB Output is correct
17 Correct 177 ms 3192 KB Output is correct
18 Correct 181 ms 3320 KB Output is correct
19 Correct 174 ms 3192 KB Output is correct
20 Correct 177 ms 3192 KB Output is correct
21 Correct 206 ms 3684 KB Output is correct
22 Correct 178 ms 3192 KB Output is correct
23 Correct 180 ms 3192 KB Output is correct
24 Correct 176 ms 3448 KB Output is correct
25 Correct 175 ms 3192 KB Output is correct
26 Correct 200 ms 3704 KB Output is correct