Remove Stones to Minimize the Total

Problem Given pile sizes and k operations — each operation picks any pile and removes floor(pile/2) stones from it — minimize the total remaining stones after exactly k operations.

Input / Output

  • Input: int array piles, int k. Output: min total stones remaining.

Constraints

  • Up to 10^5 piles, k up to 10^5.

Example

  • piles = [5,4,9], k = 2 → 12 (remove floor(9/2)=4 from 9, then floor(5/2)=2 from a 5: 18 − 4 − 2 = 12).
asked …
LeaderboardSalaryAccount