답안 #292831

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292831 2020-09-07T13:55:29 Z mat_v Sure Bet (CEOI17_sure) C++14
100 / 100
241 ms 3704 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define N 1000005

using namespace std;
using namespace __gnu_pbds;
typedef tree<pii, null_type, less<pii>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

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

int main()
{
    cin >> n;
    ff(i,1,n){
        cin >> a[i] >> b[i];
    }
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    reverse(a + 1, a + n + 1);
    reverse(b + 1, b + n + 1);
    int p1 = 1, p2 = 1;
    double s1 = 0;
    double s2 = 0;
    int kol = 0;
    double res = 0;
    while(p1 <= n || p2 <= n){
        if(p1 == n+1){
            s2 += b[p2];
            p2++;
            kol++;
            res = max(res, min(s1,s2) - kol);
            continue;
        }
        else if(p2 == n+1){
            s1 += a[p1];
            p1++;
            kol++;
            res = max(res, min(s1,s2) - kol);
            continue;
        }
        if(s1 < s2){
            s1 += a[p1];
            p1++;
            kol++;
        }
        else{
            s2 += b[p2];
            p2++;
            kol++;
        }
        res = max(res, min(s1,s2) - kol);
    }
    cout << fixed << setprecision(4) << res << "\n";
    return 0;
}

Compilation message

sure.cpp: In function 'int main()':
sure.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sure.cpp:29:5: note: in expansion of macro 'ff'
   29 |     ff(i,1,n){
      |     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 400 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 400 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 214 ms 3320 KB Output is correct
18 Correct 208 ms 3204 KB Output is correct
19 Correct 210 ms 3192 KB Output is correct
20 Correct 214 ms 3320 KB Output is correct
21 Correct 237 ms 3576 KB Output is correct
22 Correct 210 ms 3204 KB Output is correct
23 Correct 215 ms 3396 KB Output is correct
24 Correct 213 ms 3192 KB Output is correct
25 Correct 213 ms 3192 KB Output is correct
26 Correct 241 ms 3704 KB Output is correct