#K59892. Maximum Sum of Two Books

    ID: 30965 Type: Default 1000ms 256MiB

Maximum Sum of Two Books

Maximum Sum of Two Books

Bob has several books with different weights. For each test case, you are given a list of book weights. Your task is to determine the maximum possible sum of weights of two books that Bob can achieve. In other words, for each test case, select the two heaviest books and output their sum.

Let \(w_1, w_2, \dots, w_n\) be the weights of the books. The answer for one test case is:

\[ \text{answer} = \max(w_i, w_j) + \text{second max}(w_i, w_j) \quad (i \neq j) \]

You need to read the input from standard input and output the result to standard output.

inputFormat

The first line contains an integer \(T\) indicating the number of test cases.

For each test case:

  • The first line contains an integer \(n\) representing the number of books.
  • The second line contains \(n\) space-separated integers representing the weights of the books.

Input is provided via standard input (stdin).

outputFormat

For each test case, print a single integer which is the sum of the two heaviest books. Each test case's result should be printed on a new line.

Output should be written to standard output (stdout).

## sample
3
3
1 2 4
4
5 1 2 9
5
7 5 12 8 10
6

14 22

</p>