AmazonOA #20
Get Max Throughput
Estimated MediumJudge-ready
Topics (AI-labelled)Greedy
Split some of the servers into non-overlapping triples; each triple contributes the median of its three throughputs, and leftover servers may go unused. Find the maximum total contribution.
Input
The first line contains n (1..100000), and the second line contains n throughputs (1..10⁹).
Output
Output a single integer, the answer required by the problem.
Example 1
Input:
5
2 3 4 5 4
Output:
4
Example 2
Input:
2
1 2
Output:
0
Example 3
Input:
6
1 2 3 4 5 6
Output:
8
Example notes
Example 1: five servers can form at most one group; choosing throughputs 3, 4 and 5 gives median 4. Example 2: there are fewer than three servers, so no group can be formed and the answer is 0. Example 3: the servers can be split into [1,5,6] and [2,3,4], with medians 5 and 3, total 8.
Editorial
Loading solution…