#C1508. Max Total Energy
Max Total Energy
Max Total Energy
You are given a number of test cases. In each test case, you are provided with a list of energy values that represent stones placed in a line. Your task is to determine the maximum possible total energy by selecting any two stones. It is guaranteed that each test case contains at least two stones.
Mathematical Formulation:
Let \(E = [e_1, e_2, \dots, e_n]\) be the list of energies. The answer for a test case is:
\[ max_{i \neq j} (e_i + e_j) = \max(e) + \max(e \setminus \{\max(e)\}) \]Note: If the maximum value appears more than once, it is still valid to choose the same value from different positions.
inputFormat
The input is read from standard input (stdin).
The first line contains an integer (t) denoting the number of test cases.
For each test case, the first line contains an integer (n), which is the number of stones. The next line contains (n) space-separated integers representing the energy values of each stone.
outputFormat
For each test case, output the maximum possible total energy obtained by selecting any two stones. Each result should appear on a new line in the order of the test cases.## sample
2
5
-1 2 3 -4 5
3
-10 -20 30
8
20
</p>