https://www.acmicpc.net/problem/19638
import heapq
import sys
input = sys.stdin.read
def solve():
data = input().split()
N, Hcenti, T = map(int, data[:3])
giants = list(map(int, data[3:]))
max_heap = [-h for h in giants]
heapq.heapify(max_heap)
used_hammer = 0
while T > 0 and -max_heap[0] >= Hcenti:
tallest = -heapq.heappop(max_heap)
# 키가 1이면 더 줄일 수 없음
if tallest == 1:
heapq.heappush(max_heap, -tallest)
break
# 키를 절반으로 줄이고 힙에 삽입
new_height = tallest // 2
heapq.heappush(max_heap, -new_height)
used_hammer += 1
T -= 1
if -max_heap[0] < Hcenti:
print("YES")
print(used_hammer)
else:
print("NO")
print(-max_heap[0])
solve()
힙(Heap) 자료구조를 활용한 효율적인 데이터 처리 방법을 다시 복습할 수 있었다.
문제의 제약 조건을 분석하고 이를 충족시키기 위한 세부 처리 로직의 중요성을 확인했다.