BOJ - 1417 - 국회의원 선거

Updated:


import sys

def solution():
    N = int(sys.stdin.readline())
    ret = 0
    vote = []
    myVote = int(sys.stdin.readline())
    for _ in range(N-1):
        vote.append(int(sys.stdin.readline()))

    while True:
        vote.sort(reverse=True)
        check = False
        for i in range(len(vote)):
            if myVote <= vote[i]:
                myVote += 1
                vote[i] -= 1
                ret +=1
                check = True
                break
        if not check:
            break
    print(ret)

solution()

https://www.acmicpc.net/problem/1417

Categories:

Updated:

Leave a comment