AmazonOA #210
Get Maximum Throughput
Estimated MediumJudge-ready
Topics (AI-labelled)GreedyIn-place Arrays
Each group has three servers, and a group's throughput is the median of the three. Each server joins at most one group, and some servers may go unused. Find the maximum total throughput over all groups.
Input
The first line contains n; the second line contains the throughputs. 1≤n≤200000, 1≤throughput≤10^9.
Output
Output a single integer, the answer.
Example 1
Input:
6
4 6 3 5 4 5
Output:
9
Example 2
Input:
5
2 3 4 3 4
Output:
4
Example 3
Input:
2
9 1
Output:
0
Example notes
The answers are 9, 4 and 0. With fewer than three servers no group can be formed.
Editorial
Loading solution…