CF2019A.Max Plus Size

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

Max Plus Size

EnV - Dynasty

You are given an array a1,a2,,ana_1, a_2, \ldots, a_n of positive integers.

You can color some elements of the array red, but there cannot be two adjacent red elements (i.e., for 1in11 \leq i \leq n-1, at least one of aia_i and ai+1a_{i+1} must not be red).

Your score is the maximum value of a red element plus the number of red elements. Find the maximum score you can get.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1001 \le n \le 100) — the length of the array.

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 given array.

Output

For each test case, output a single integer: the maximum possible score you can get after coloring some elements red according to the statement.

Note

In the first test case, you can color the array as follows: [5,4,5][\color{red}{5}, 4, \color{red}{5}]. Your score is max([5,5])+size([5,5])=5+2=7\max([5, 5]) + \text{size}([5, 5]) = 5+2 = 7. This is the maximum score you can get.

In the second test case, you can color the array as follows: [4,5,4][\color{red}{4}, 5, \color{red}{4}]. Your score is max([4,4])+size([4,4])=4+2=6\max([4, 4]) + \text{size}([4, 4]) = 4+2 = 6. This is the maximum score you can get.

In the third test case, you can color the array as follows: $[\color{red}{3}, 3, \color{red}{3}, 3, \color{red}{4}, 1, 2, \color{red}{3}, 4, \color{red}{5}]$. Your score is $\max([3, 3, 4, 3, 5]) + \text{size}([3, 3, 4, 3, 5]) = 5+5 = 10$. This is the maximum score you can get.

Samples

4
3
5 4 5
3
4 5 4
10
3 3 3 3 4 1 2 3 4 5
9
17 89 92 42 29 92 14 70 45
7
6
10
97

在线编程 IDE

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