Agorithm/백준 알고리즘
백준 알고리즘 1417번 국회의원 선거(python)
kimjinho1
2021. 3. 23. 14:23
728x90
반응형
기본적인 우선순위 큐 문제이다. 최대 힙으로 구현해주면 된다.
import heapq
N = int(input())
D = int(input())
q = []
for _ in range(N-1):
n = int(input())
heapq.heappush(q, -n)
res = 0
while q:
n = -heapq.heappop(q)
if D > n:
break
D += 1
res += 1
heapq.heappush(q, -(n-1))
print(res)
728x90
반응형