Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Remove Stones to Minimize the Total

XPChallenge Points: 20
levelLevel: Medium

You are given an array piles, where piles[i] indicates how many stones are in the ith pile.
You also have an integer k, meaning you must perform exactly k operations.

In one operation, select any pile and remove floor(piles[i] / 2) stones from it.
You are allowed to choose the same pile multiple times.

Your task is to return the smallest total number of stones that can remain in all piles after performing the operation exactly k times.

Example 1:

Input: piles = [8, 3, 10], k = 2

Output: 15

Explanation:

Choose pile 10: remove floor(10/2) = 5 → piles: [8,3,5] Choose pile 8: remove floor(8/2) = 4 → piles: [4,3,5] Total = 4 + 3 + 5 = 12.

Example 2:

Input: piles = [1, 2, 3, 4], k = 1

Output: 8

Explanation:

Best move is on pile 4: remove floor(4/2) = 2 → [1,2,3,2] Sum = 8.

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result