Easiest Python solution with heap


#1
from heapq import heappush,heappop
    class Solution:
        # @param A : list of integers
        # @param B : integer
        # @return an integer
        def solve(self, arr, k):
            q=[]
            ans=0
            for i in range(len(arr)):
                heappush(q,-arr[i])
            while k:
                top=heappop(q)
                ans+=-top
                top+=1
                if top!=0:
                    heappush(q,top)
                k-=1
            return ans