답안 #498437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498437 2021-12-25T08:03:08 Z AQ0212 Sure Bet (CEOI17_sure) C++17
0 / 100
0 ms 296 KB
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <cstring>

// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#define ll long long int
#define pb push_back
#define pll pair < ll , ll >
#define fi first
#define se second
#define all(x) x.begin(), x.end()

using namespace std;

ll inf2 = 3e18;

double a[ 100111 ], b[ 100111 ], sum1, sum2, sit1, sit2, cnt, grnt;
pair < double , double > c[ 100111 ];
vector < pll > unused, overused;

int main(){
    ll n;

    cin >> n;

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

        // c[ i ].fi = a[ i ];
        // c[ i ].se = b[ i ];
    }

    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);

    sum1 = a[ n ];
    sum2 = b[ n ];
    cnt = 2.0;
    grnt = min(sum1 - cnt, sum2 - cnt);
        
    for(int i = n - 1; i >= 1; i --){
        if(a[ i ] > b[ i ]){
            if(sum1 + a[ i ] - (cnt + 1) > grnt && sum2 - (cnt + 1) > grnt){
                sum1 += a[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }else if(sum1 + a[ i ] - (cnt + 1) > grnt && sum2 + b[ i ] - (cnt + 1) > grnt){
                sum1 += a[ i ];
                sum2 += b[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }else if(sum1 - (cnt + 2) > grnt && sum2 + b[ i ] - (cnt + 2) > grnt){
                sum2 += b[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }
        }else{
            if(sum1 - (cnt + 1) > grnt && sum2 + b[ i ] - (cnt + 1) > grnt){
                sum2 += b[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }else if(sum1 + a[ i ] - (cnt + 2) > grnt && sum2 + b[ i ] - (cnt + 2) > grnt){
                sum1 += a[ i ];
                sum2 += b[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }else if(sum1 + a[ i ] - (cnt + 1) > grnt && sum2 - (cnt + 1) > grnt){
                sum1 += a[ i ];
                cnt ++;
                grnt = min(sum1 - cnt, sum2 - cnt);
            }
        }
    }

    printf("%.4lf", max(0.0, grnt));
}

/*

4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5

*/

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 296 KB Output isn't correct
4 Halted 0 ms 0 KB -