코드포스(CodeForce)

Educational Codeforces Round 27 - A. Chess Tourney

cepiloth 2018. 8. 17. 18:08
반응형


1. 문제


2. 알고리즘

키워드 - 구현


* 문제 접근

항상 BerOil 이 후원하는 팀은 승리 해야 한다.



* 제약 사항

rating 이 큰 플레이어가 승리 한다.

rating 이 같으면 둘 중에 하나가 승리 한다.

입력 받는 rating 은 무작위로 들어 온다.



* 풀이

입력 받는 rating 을 내림 차순으로 정렬 한다.

mid 값 즉 처음 입력 받는 값을 mid 로 정한다.

left 팀은 a[mid] right 팀은 a[mid+1]

제약사항을 적용 하고 출력 한다.


3. 코드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdio.h>
 
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
 
using namespace std;
 
int main() {
 
    int n;
    cin >> n;
 
    vector<int> arr(n*2);
    for(int i=0;i<n*2; i++) {
        cin >> arr[i];
    }
 
    sort(arr.begin(), arr.end());
 
    int sol = arr[n-1< arr[min(n+1, n)] ? 0;
 
    if(sol) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
 
    }
    return 0;
}
cs

반응형