piles[i] being the number of coins in pile i. The game lasts rounds rounds. In each round you pick the tallest pile (any of them if there is a tie) and take coins from it so that ⌊√x⌋ remain, where x is how many it had.
Return the total number of coins left on the table across all piles after the last round.piles=[50, 10, 3], rounds=3 → 8
First 50 → 7, then the tallest pile is 10 → 3, then 7 → 2. That leaves 2 + 3 + 3 = 8.
piles=[100], rounds=5 → 1
100 → 10 → 3 → 1, and after that a pile of one coin no longer shrinks.
piles=[50, 10, 3], rounds=3
8
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.