답안 #498477

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498477 2021-12-25T09:38:50 Z AQ0212 Sure Bet (CEOI17_sure) C++17
0 / 100
0 ms 204 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, cnt, grnt, agrnt;
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 ];
    }

    if(n == 1){
        cout << max(0.0, min(a[ 1 ] - 2, b[ 1 ] - 2));
        return 0;
    }

    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 --){
        double sit1a, sit1b, sit2a, sit2b, sit3a, sit3b, grnt1, grnt2, grnt3;

        sit1a = sum1 + a[ i ] - (cnt + 1);
        sit1b = sum2 - (cnt + 1);
        grnt1 = min(sit1a, sit1b);

        sit2a = sum1 - (cnt + 1);
        sit2b = sum2 + b[ i ] - (cnt + 1);
        grnt2 = min(sit2a, sit2b);

        sit3a = sum1 + a[ i ] - (cnt + 2);
        sit3b = sum2 + b[ i ] - (cnt + 2);
        grnt3 = min(sit3a, sit3b);

        if(grnt3 > grnt){
            sum1 += a[ i ];
            sum2 += b[ i ];
            cnt += 2;
            grnt = grnt3;
            // cout << "3)";
        }else if(grnt1 >= grnt2 && grnt1 >= grnt3 && grnt1 > grnt){
            sum1 += a[ i ];
            cnt ++;
            grnt = grnt1;
            // cout << "1)";
        }else if(grnt2 > grnt1 && grnt2 >= grnt3 && grnt2 > grnt){
            sum2 += b[ i ];
            cnt ++;
            grnt = grnt2;
            // cout << "2)";
        }
        // else if(grnt3 > grnt2 && grnt3 > grnt1 && grnt3 > grnt){
        //     sum1 += a[ i ];
        //     sum2 += b[ i ];
        //     cnt += 2;
        //     grnt = grnt3;
        //     cout << "3)";
        // }

        // cout << " sum1:" << sum1 << " sum2:" << sum2 << " grnt:" << grnt << " grnt1:" << grnt1 << " grnt2:" << grnt2 << " grnt3:" << grnt3 << "\n";
    }

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

/*

4
1.4 3.7
1.2 2
1.6 1.4
1.9 1.5

10
1 2
3 4
4 7
9 3
5 4
1.5 5.6
4.3 4.5
9.8 3.4
3.2 4.3
5.6 7.3

*/

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