• + 0 comments

    def cookies(k,A): # convert list A to priority queue heapq heapq.heapify(A)

    iteration = 0
    while any(c < k for c in A) and len(A) > 1:
        mix = heapq.heappop(A) + 2 * heapq.heappop(A)
        heapq.heappush(A,mix)
        iteration += 1
    
    
    if not all(c >= k for c in A):
        return -1
    
    return iteration