프로그래밍/HackerRank
[HackerRank][Python3] Jesse and Cookies
snoopybox
2018. 9. 9. 16:31
Problem :
https://www.hackerrank.com/challenges/jesse-and-cookies/problem
My Solution :
#!/usr/bin/env python3
from heapq import heappush, heappop, heapify
def cookies(k, A):
heapify(A)
count = 0
if k <= A[0]:
return count
while len(A) > 1:
heappush(A, heappop(A)+2*heappop(A))
count += 1
if k <= A[0]:
return count
return -1
n, k = map(int, input().split())
A = list(map(int, input().rstrip().split()))
result = cookies(k, A)
print(result)
Comment :
최소 힙 자료구조로 쉽게 해결할 수 있는 문제이다. heap 자체를 구현하라는 문제는 아닌 것 같아서 그냥 import 하여 처리하였다.