반응형
문제
https://www.acmicpc.net/problem/19638
해설
최대 힙을 사용하는 문제였다.
# PyPy3
import heapq
def solution(target, cnt, heap):
heapq.heapify(heap)
hammer_cnt = 0
for _ in range(cnt):
height = -heap[0]
if height == 1 or height < target:
break
else:
hammer_cnt += 1
heapq.heapreplace(heap, -(height // 2))
if target <= -heap[0]:
print("NO")
print(-heapq.heappop(heap))
else:
print("YES")
print(hammer_cnt)
popularity, h_centi, count = map(int, input().split())
giant_lst = [-int(input()) for _ in range(popularity)]
solution(h_centi, count, giant_lst)
반응형