You are given an array piles containing 3n piles of coins. Three players — Alice, You, and Bob — repeatedly take turns selecting coins under the following rule:
In each round, you choose any three piles.
Alice always takes the pile with the highest number of coins.
You take the pile with the second-highest coins.
Bob receives the remaining pile.
This process continues until all piles are taken.
Your goal is to maximize the total coins you obtain.
Return the maximum coins you can collect.
Input: piles = [3, 1, 9, 6, 2, 8]
Output: 11
Explanation:
Sorted piles → [1,2,3,6,8,9] Pick triplets optimally: (3, 8, 9) → You take 8 (1, 2, 6) → You take 2 Total = 8 + 4 = 12
Input: piles = [5, 2, 9]
Output: 5
Explanation:
Only one triplet → Alice takes 9, you take 5, Bob gets 2.
Input: piles = [10, 1, 7, 4, 3, 9, 8, 2, 6]
Output: 20
Accepted:
Submission: