Skip to content

Commit ffd1de1

Browse files
committed
[BOJ] #19638.센티와 마법의 뿅망치 / 실버1 / 50(∆)
1 parent 8e4042b commit ffd1de1

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sys
2+
input = sys.stdin.readline
3+
import heapq
4+
5+
N, Hcenti, T = map(int, input().split())
6+
giants = [-int(input().strip()) for _ in range(N)] # 최대 힙을 위해 음수 변환
7+
8+
# 최대 힙 생성
9+
heapq.heapify(giants)
10+
used_hammer = 0 # 사용한 뿅망치 횟수
11+
12+
# 마법의 뿅망치를 사용
13+
for _ in range(T):
14+
tallest = -heapq.heappop(giants) # 가장 큰 거인 추출
15+
16+
if tallest < Hcenti: # 센티보다 작아졌다면 종료
17+
heapq.heappush(giants, -tallest)
18+
break
19+
20+
if tallest == 1: # 키가 1이면 줄일 수 없으므로 다시 넣고 종료
21+
heapq.heappush(giants, -tallest)
22+
break
23+
24+
new_height = tallest // 2 # 키 줄이기
25+
heapq.heappush(giants, -new_height) # 줄인 값 다시 삽입
26+
used_hammer += 1 # 사용 횟수 증가
27+
28+
# 가장 키가 큰 거인 확인 (힙이 비었으면 0)
29+
tallest_remaining = -heapq.heappop(giants) if giants else 0
30+
31+
if tallest_remaining < Hcenti:
32+
print("YES")
33+
print(used_hammer)
34+
else:
35+
print("NO")
36+
print(tallest_remaining)

0 commit comments

Comments
 (0)