File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ """
2+ #19638. 센팀와 마법의 뿅망치
3+ https://www.acmicpc.net/problem/19638
4+ # 문제 조건
5+ 1. 입력 : 인구수 N , 대조군 키 H , 횟수 제한 T / 거인 키 n1, n2 ...
6+ 2. L -> L/2 //
7+ 3. T 개 안에 H > N개키
8+ # flow
9+ goal) 키가 큰 거인 선택 -> 때리기
10+ - 최소 길이 1 => H = 1, -> 무조건 No
11+ # 문제 핵심
12+ - sort 사용시 런타임 에러
13+ - 따라서 heapq가 핵심
14+ """
15+
16+ import sys
17+ import heapq
18+ N , H , threshold = list (map (int , sys .stdin .readline ().split ()))
19+
20+ heights = []
21+ for i in range (N ) :
22+ h = int (sys .stdin .readline ())
23+ heapq .heappush (heights ,- 1 * h )
24+ # heights.append(h)
25+
26+
27+
28+ cnt = 0
29+ for trial in range (threshold + 1 ) :
30+ current_top = - 1 * heapq .heappop (heights )
31+ if current_top == 1 or H > current_top : # 중간 종료 조건 : (1)
32+ break
33+
34+ if trial >= threshold :
35+
36+ break
37+
38+ heapq .heappush (heights , - 1 * (current_top // 2 ))
39+
40+ #1. 가장 큰 거인 VS 센티의 키 차이 비교
41+
42+ if H > current_top :
43+ print ("YES" )
44+ print (trial )
45+ else :
46+ print ("NO" )
47+ print (current_top )
You can’t perform that action at this time.
0 commit comments