#P6631. [ZJOI2020] 序列

[ZJOI2020] 序列

Description

Bob likes sequences.

There is a non-negative integer sequence a1,a2,,ana_1, a_2,\cdots, a_n of length nn. In each step, you may choose one of the following three operations to perform:

  • Choose an interval [l,r][l, r], and subtract 11 from all numbers whose indices are in this interval.

  • Choose an interval [l,r][l, r], and subtract 11 from all numbers in this interval whose indices are odd.

  • Choose an interval [l,r][l, r], and subtract 11 from all numbers in this interval whose indices are even.

Find the minimum number of steps needed to make all numbers in the sequence become 00.

Input Format

The first line contains an integer TT, which denotes the number of test cases.

For each test case, the first line contains an integer nn. The next line contains nn non-negative integers a1,a2,,ana_1, a_2,\dots, a_n.

Output Format

Output TT lines. For each test case, output one integer per line, which is the answer.

3
5
2 1 2 1 2
8
1000000000 1000000000 0 1000000000 1000000000 0 1000000000 1000000000
13
1 1 4 5 1 4 1 9 1 9 8 1 0
2
3000000000
19

Hint

Sample explanation 11.

Test case 1: $21212 \stackrel{1}{\longrightarrow} 1111 1 \stackrel{1}{\longrightarrow} 00000$.

Test case 3: $1145141919810 \stackrel{1}{\longrightarrow} 0034030808700 \stackrel{8}{\longrightarrow} 0031000000700 \stackrel{10}{\longrightarrow}0000000000000$.

Sample input and output 22 are provided in the attached file.

Constraints:

For the first 10%10\% of the testdata, n5,ai10n \leq 5, a_i \leq 10.

For the first 30%30\% of the testdata, n50,ai50n \leq 50, a_i \leq 50.

For the first 50%50\% of the testdata, n200,ai200n \leq 200, a_i \leq 200.

For the first 60%60\% of the testdata, n200,ai109n \leq 200, a_i \leq 10^9.

For the first 70%70\% of the testdata, n1000,ai109n \leq 1000, a_i \leq 10^9.

For the first 90%90\% of the testdata, n10000,ai109n \leq 10000, a_i \leq 10^9.

For 100%100\% of the testdata, $1 \leq n \leq 100000, 0 \leq a_i \leq 10^9, 1 \leq T \leq 10$.

Translated by ChatGPT 5