CF1991A.Maximize the Last Element

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

Maximize the Last Element

You are given an array aa of nn integers, where nn is odd.

In one operation, you will remove two adjacent elements from the array aa, and then concatenate the remaining parts of the array. For example, given the array [4,7,4,2,9][4,7,4,2,9], we can obtain the arrays [4,2,9][4,2,9] and [4,7,9][4,7,9] by the operations [4,7,4,2,9][4,2,9][\underline{4,7}, 4,2,9] \to [4,2,9] and [4,7,4,2,9][4,7,9][4,7,\underline{4,2},9] \to [4,7,9] respectively. However, we cannot obtain the array [7,2,9][7,2,9] as it requires deleting non-adjacent elements [4,7,4,2,9][\underline{4},7,\underline{4},2,9].

You will repeatedly perform this operation until exactly one element remains in aa.

Find the maximum possible value of the remaining element in aa.

Input

Each test contains multiple test cases. The first line contains a single integer tt (1t10001 \le t \le 1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains a single integer nn (1n991 \le n \le 99; nn is odd) — the length of the array aa.

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

Note that there is no bound on the sum of nn over all test cases.

Output

For each test case, output a single integer — the maximum possible value of the remaining element in aa.

Note

In the first test case, the array aa is [6][6]. Since there is only one element, no operations are needed. The maximum possible value of the remaining element is 66.

In the second test case, the array aa is [1,3,2][1, 3, 2]. We can remove the first two elements [1,3,2][2][\underline{1, 3}, 2] \to [2], or remove the last two elements [1,3,2][1][1, \underline{3, 2}] \to [1]. Therefore, the maximum possible value of the remaining element is 22.

In the third test case, the array aa is [4,7,4,2,9][4, 7, 4, 2, 9]. One way to maximize the remaining element is $[4, \underline{7, 4}, 2, 9] \to [\underline{4, 2}, 9] \to [9]$. Therefore, the maximum possible value of the remaining element is 99.

In the fourth test case, the array aa is [3,1,4,1,5,9,2][3, 1, 4, 1, 5, 9, 2]. It can be shown that the maximum possible value of the remaining element is 55.

Samples

4
1
6
3
1 3 2
5
4 7 4 2 9
7
3 1 4 1 5 9 2
6
2
9
5

在线编程 IDE

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