prices[i] is the price of fruit number i + 1 (numbered from one).
The seller runs a promotion: buy fruit number i and you may take any of the next i fruits (numbers i + 1 through 2i) for free. A fruit you could take for free may still be bought, to get its own bonus.
Return the least amount you need to pay to take home every fruit.prices=[4, 2, 9, 9] → 6
Buy fruit 1 for 4 and fruit 2 comes free; buy fruit 2 anyway for 2 and fruits 3 and 4 come free. Total 6.
prices=[2, 7, 1, 8, 3] → 3
Buy fruit 1 (2), take fruit 2 free, buy fruit 3 (1), which covers fruits 4 and 5. Total 3.
prices=[5] → 5
prices=[4, 2, 9, 9]
6
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.