CF2074B.The Third Side

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

The Third Side

The pink soldiers have given you a sequence aa consisting of nn positive integers.

You must repeatedly perform the following operation until there is only 11 element left.

  • Choose two distinct indices ii and jj.
  • Then, choose a positive integer value xx such that there exists a non-degenerate triangle^{\text{∗}} with side lengths aia_i, aja_j, and xx.
  • Finally, remove two elements aia_i and aja_j, and append xx to the end of aa.

Please find the maximum possible value of the only last element in the sequence aa.

^{\text{∗}}A triangle with side lengths aa, bb, cc is non-degenerate when a+b>ca+b \gt c, a+c>ba+c \gt b, b+c>ab+c \gt a.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t1041 \le t \le 10^4). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051 \le n \le 2 \cdot 10^5).

The second line of each test case contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai10001 \le a_i \le 1000) — the elements of the sequence aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output the maximum possible value of the only last element on a separate line.

Note

On the first test case, there is already only one element. The value of the only last element is 1010.

On the second test case, aa is initially [998,244,353][998,244,353]. The following series of operations is valid:

  1. Erase a2=244a_2=244 and a3=353a_3=353, and append 596596 to the end of aa. aa is now [998,596][998,596].
  2. Erase a1=998a_1=998 and a2=596a_2=596, and append 15931593 to the end of aa. aa is now [1593][1593].

It can be shown that the only last element cannot be greater than 15931593. Therefore, the answer is 15931593.

Samples

4
1
10
3
998 244 353
5
1 2 3 4 5
9
9 9 8 2 4 4 3 5 3
10
1593
11
39

在线编程 IDE

建议全屏模式获得最佳体验