-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreSpicy.py
More file actions
59 lines (44 loc) · 1.27 KB
/
Copy pathMoreSpicy.py
File metadata and controls
59 lines (44 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# 10. 더 맵게
import heapq as hq
def solution(scovile, K):
answer = 0
hq.heapify(scovile)
while scovile[0] < K:
mix_scov = hq.heappop(scovile) + hq.heappop(scovile) * 2
hq.heappush(scovile, mix_scov)
answer += 1
if len(scovile) == 1 and scovile[0] < K:
return -1
return answer
scovile_1 = [1, 2, 3, 9, 10, 12]
K_1 = 7
print(solution(scovile_1, K_1))
# 가장 작은 값을 생각하자!! ... 힙 안 쓰면 초과 걸리네
def solution_error(scovile, K):
answer = 0
scovile.sort(reverse = True)
while scovile[len(scovile) - 1] < K:
try:
scovile.append(scovile.pop() + scovile.pop() * 2)
except IndexError:
answer = -1
return answer
answer += 1
return answer
# print(solution_error(scovile_1, K_1))
'''
'''
def solution_other(scovile, K):
answer = 0
heap = []
for num in scovile:
hq.heappush(heap, num)
while heap[0] < K:
try:
hq.heappush(heap, hq.heappop(heap) + (hq.heappop(heap) * 2))
except IndexError:
answer = -1
return answer
answer += 1
return answer
# print(solution_other(scovile_1, K_1))