There are 3n piles of coins. Repeatedly choose any 3 piles: Alice takes the largest, you take the next largest, and Bob takes the last one. Continue until no piles remain. Given piles, return the maximum number of coins you can have.
There are 3n piles of coins. Repeatedly choose any 3 piles: Alice takes the largest, you take the next largest, and Bob takes the last one. Continue until no piles remain. Given piles, return the maximum number of coins you can have.
Example 1:
Input: {"piles":[2,4,1,2,7,8]}
Output: 9
Constraints:
3≤piles.length≤105
piles.lengthmod3=0
1≤piles[i]≤104
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"piles":[2,4,1,2,7,8]}
6 piles, so 2 rounds of three. Alice always grabs the biggest pile of a triple and Bob the smallest, so you want every triple to be "two big piles plus one tiny one".