You are viewing a single comment's thread. Return to all comments →
solution for python 3 using heapq
from heapq import heappop,heappush,heapify firstLine = [int(x) for x in input().split()] cookies = [int(x) for x in input().split()] cookieCount = int(firstLine[0]) minSweetness = int(firstLine[1]) heapify(cookies) fC = 0 try: while cookies[0] < minSweetness: fC+=1 c1 = heappop(cookies) c2 = heappop(cookies) newCookie=(1*c1)+(2*c2) heappush(cookies,newCookie) print(fC) except: print("-1")
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
solution for python 3 using heapq