3n bags of coins; bag i holds bags[i] coins. The split goes in rounds:
- you put any three of the remaining bags on the table;
- Anya takes the richest of them;
- you take the richer of the two that are left;
- Boris takes the last one.
Rounds go on until no bags remain. Return the largest number of coins you can end up with.bags=[5, 1, 3, 8, 2, 6] → 9
First put out 8, 6 and 1: Anya takes 8, you take 6, Boris takes 1. Then 5, 3 and 2: you get 3. That is 6 + 3 = 9.
bags=[4, 4, 4] → 4
There are only three bags and they are all equal, so you get 4.
bags=[10, 1, 1, 1, 9, 9, 2, 3, 7] → 18
bags[i] ≤ 10⁴bags=[5, 1, 3, 8, 2, 6]
9
Run checks the first 3 tests in your browser. Submit checks all 65 tests on the server, hidden ones included.