반응형
문제
https://www.acmicpc.net/problem/1417
해설
최대 힙을 활용하는 문제였다.
import heapq
def solution(target, heap):
heapq.heapify(heap)
if not len(heap):
return 0
answer = 0
while target <= -heap[0]:
answer += 1
target += 1
heapq.heapreplace(heap, heap[0] + 1)
return answer
candidate = int(input())
vote = [-int(input()) for _ in range(candidate)]
print(solution(-vote[0], vote[1:]))
반응형