1962. Remove Stones to Minimize the Total
class Solution:
def minStoneSum(self, piles: List[int], k: int) -> int:
heap = []
answer = 0
for pile in piles:
heapq.heappush(heap, (-pile, pile))
for _ in range(k):
x = heapq.heappop(heap)[1]
x = ceil(x/2)
heapq.heappush(heap, (-x, x))
return sum([node[1] for node in heap])
class Solution:
def minStoneSum(self, piles: List[int], k: int) -> int:
heap = [-pile for pile in piles]
heapq.heapify(heap)
for _ in range(k):
heapq.heapreplace(heap, heap[0] // 2)
return -sum(heap)