---
title: "1962. Remove Stones to Minimize the Total"
url: "https://laigary.com/interview/coding/1962-remove-stones-to-minimize-the-total"
type: "note"
section: "coding"
date: "2025-03-30"
updated: "2025-03-30"
tags: ["Greedy", "Heap"]
---

# 1962. Remove Stones to Minimize the Total

[1962\. Remove Stones to Minimize the Total](https://leetcode.com/problems/remove-stones-to-minimize-the-total/)

```python
class Solution:
    def minStoneSum(self, piles: List[int], k: int) -> int:
        heap = []
        for pile in piles:
            heapq.heappush(heap, -pile)
        
        while k > 0:
            top = heapq.heappop(heap)
            heapq.heappush(heap, floor(top / 2))
            k -= 1
        
        return sum([-pile for pile in heap])
```
