[알고리즘/백준]1489 : 대결(python)

유현민·2022년 9월 13일
0

알고리즘

목록 보기
251/253

점수를 가장 크게 만들려면 승리를 우선순위로 두어야 한다.
또한 b 팀에서 자기보다 작은 수 중에서 가장 큰 수를 이겨야 최대가 된다.
이기는 경우를 다 구한 후 무승부 경우를 구하면 된다.

sort에서 reverse를 해준 이유는 큰 수부터 비교를 해야 for문이 일찍 끝나기 때문이다.

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort(reverse=True)
score = 0

# 승리
for i in range(n):
    for j in range(n):
        if a[i] > b[j] != 0:
            score += 2
            a[i] = 0
            b[j] = 0
            break

# 무승부
for i in range(n):
    if a[i] == 0:
        continue
    for j in range(n):
        if a[i] == b[j] != 0:
            score += 1
            b[j] = 0
            break

print(score)
profile
smilegate megaport infra

0개의 댓글