Skip to content

Commit e3baab7

Browse files
committed
[BOJ] #19638. 센티와 마법의 뿅망치 / 실버1 / 60분 / 힌트
1 parent 7a6e4e3 commit e3baab7

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+
import heapq
3+
4+
input = sys.stdin.readline
5+
6+
# 입력
7+
N, H, T = map(int, input().split()) # N: 거인의 나라 인구 수, H: 센티의 키, T: 뿅망치 횟수 제한
8+
heights = []
9+
10+
for _ in range(N):
11+
heapq.heappush(heights, -int(input())) # 최대힙을 위해 음수로 저장
12+
13+
cnt = 0 # 사용한 뿅망치 개수
14+
15+
# 뿅망치 사용
16+
while cnt < T:
17+
tallest = -heapq.heappop(heights) # 가장 큰 키를 가져옴
18+
19+
if tallest < H: # 센티보다 작은 거인이 나오면 즉시 종료
20+
print(f"YES\n{cnt}")
21+
break
22+
23+
# 키가 1이면 더 줄일 수 없음
24+
if tallest == 1:
25+
heapq.heappush(heights, -1)
26+
else:
27+
heapq.heappush(heights, -(tallest // 2))
28+
29+
cnt += 1
30+
else:
31+
# 뿅망치 사용을 모두 소진한 경우
32+
tallest_after = -heapq.heappop(heights) # 남아 있는 가장 큰 키
33+
if tallest_after < H:
34+
print(f"YES\n{cnt}")
35+
else:
36+
print(f"NO\n{tallest_after}")

0 commit comments

Comments
 (0)