#C7257. Maximum Team Effectiveness
Maximum Team Effectiveness
Maximum Team Effectiveness
You are given T test cases. In each test case, there are N participants with their corresponding skill values. Your task is to form a team consisting of exactly three participants such that their total effectiveness (i.e. the sum of their skill values) is maximized.
More formally, for each test case, if the skills are given as a sequence \(a_1, a_2, \dots, a_N\), you need to compute the value \[ E = a_{i} + a_{j} + a_{k} \] where \(a_{i}\), \(a_{j}\), and \(a_{k}\) are the three largest numbers in the sequence. It is guaranteed that \(N \ge 3\) for every test case.
Input and Output via Standard I/O: Read input from stdin
and write output to stdout
.
inputFormat
The first line contains an integer T, the number of test cases. Each test case is described in one line as follows:
- The test case starts with an integer N (\(N \ge 3\)), the number of participants.
- Then follow N space-separated integers representing the skill values of the participants.
For example:
3 5 10 20 30 40 50 4 7 1 8 12 6 5 5 5 5 5 5
outputFormat
For each test case, output a single line containing one integer — the maximum effectiveness of the team, which is the sum of the three largest skill values.
For example, the output corresponding to the sample input above would be:
120 27 15## sample
3
5 10 20 30 40 50
4 7 1 8 12
6 5 5 5 5 5 5
120
27
15
</p>