백준 1417번: 국회의원 선거 #Python

ColorlessDia·2025년 2월 8일

algorithm/baekjoon

목록 보기
447/836
import sys
from heapq import heappush, heappop

input = sys.stdin.readline

vote_count = 0
max_vote = []

N = int(input())

for candidate in range(1, N + 1):
    vote = int(input())

    if candidate == 1:
        vote_count = vote
        continue

    heappush(max_vote, -vote)

buy_count = 0

while 0 < len(max_vote):
    vote = -heappop(max_vote)
    
    if vote < vote_count:
        break
    
    heappush(max_vote, -(vote - 1))

    buy_count += 1
    vote_count += 1

print(buy_count)

0개의 댓글