• + 0 comments
    import heapq
    
    def cookies(k, A):
        h=[i for i in A]
        heapq.heapify(h)
        ans=0
        while h[0]<k and len(h)>1:
            f=heapq.heappop(h)
            s=heapq.heappop(h)
            heapq.heappush(h,f+2*s)
            ans+=1
            
        if h[0]>=k:
            return ans
        else:
            return -1