CF2013B.Battle for Survive

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

Battle for Survive

Eralim, being the mafia boss, manages a group of nn fighters. Fighter ii has a rating of aia_i.

Eralim arranges a tournament of n1n - 1 battles, in each of which two not yet eliminated fighters ii and jj (1i<jn1 \le i \lt j \le n) are chosen, and as a result of the battle, fighter ii is eliminated from the tournament, and the rating of fighter jj is reduced by the rating of fighter ii. That is, aja_j is decreased by aia_i. Note that fighter jj's rating can become negative. The fighters indexes do not change.

Eralim wants to know what maximum rating the last remaining fighter can preserve if he chooses the battles optimally.

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 (2n21052 \le n \le 2 \cdot 10^5) — the number of fighters.

The second line of each test case contains nn integers a1,a2,ana_1, a_2, \ldots a_n (1ai1091 \le a_i \le 10^9) — the ratings of the fighters.

The sum of nn over all testcases does not exceed 21052 \cdot 10^5.

Output

For each testcase, output a single integer — the maximum rating that the last remaining fighter can preserve.

Note

In the first example, you can arrange a fight between fighters with indices 11 and 22, where the fighter with index 22 will win. The rating of the last fighter, that is, the fighter with index 22, will be 12=11 - 2 = -1.

In the second example, you can first conduct a fight between fighters with indices 11 and 22, where the fighter with index 22 will win, and then conduct a fight between fighters with indices 22 and 33, where the fighter with index 33 will win.

The rating of the fighter with index 22 after the first fight will be 22=02 - 2 = 0. The rating of the fighter with index 33 after the second fight will be 80=88 - 0 = 8.

Samples

5
2
2 1
3
2 2 8
4
1 2 4 3
5
1 2 3 4 5
5
3 2 4 5 4
-1
8
2
7
8

在线编程 IDE

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