Python easy solution using heaps


#1

import heapq
A=[-i for i in A]
res=[]
heapq.heapify(A)
for i in range(B):
res.append(-1*(heapq.heappop(A)))
return(res)