n cups of ice cream on the counter; cup i holds a portion of size scoops[i]. You take exactly k cups, one per turn.
After every turn, each cup still on the counter melts a little: its portion shrinks by 1, but never below zero.
Return the largest possible total size of the portions you take.scoops=[2, 6, 4], k=2 → 9
Take the 6 first. The rest melt to [1, 3], so the second pick gets 3. That is 6 + 3 = 9.
scoops=[1, 1, 2], k=3 → 2
Take the 2; the two 1s melt down to nothing, and the remaining picks add 0: 2 + 0 + 0 = 2.
scoops=[5, 5, 5, 5], k=4 → 14
n = len(scoops) ≤ 2·10⁵scoops[i] ≤ 10⁸k ≤ nscoops=[2, 6, 4], k=2
9
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.