Problem 979
Maximum Number of Coins You Can Get
Medium · 20 pts · Array, Greedy, Sorting, Game Theory
Problem
There are 3N piles of coins. In each round you choose any three piles; Alice takes the largest, you take the second largest, and Bob takes the smallest. Repeat until no piles are left. Maximise the number of coins you get. Sort the piles: give Bob the N smallest piles, and in each round pair the two largest remaining piles, so you take every second pile from the top among the largest 2N.
Input
The first line contains 3N, the number of piles. The second line contains the pile sizes.
Output
Print the maximum number of coins you can get.
Constraints
3 <= 3N <= 100000; 3N is a multiple of 3; 1 <= pile <= 10^4
Example input
6 2 4 1 2 7 8
Example output
9
Explanation
For 2 4 1 2 7 8, choose (1, 7, 8) to get 7 and (2, 2, 4) to get 2, for a total of 9, the best possible.