We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
while len(A)>1 and A[0]<k and (A[1]<k or A[2]<k):
a=heappop(A)
b=heappop(A)
heappush(A,a+2*b)
iterations+=1
if len(A)==1:
if A[0] >= k:
return iterations
else:
return -1
else:
if A[0] >= k:
return iterations
else:
return iterations + 1
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
A = list(map(int, input().rstrip().split()))
result = cookies(k, A)
fptr.write(str(result) + '\n')
fptr.close()
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
from heapq import heappush,heappop,heapify
def cookies(k, A): heapify(A) iterations=0
if name == 'main': fptr = open(os.environ['OUTPUT_PATH'], 'w')