CF2031A.Penchick and Modern Monument

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

Penchick and Modern Monument

Amidst skyscrapers in the bustling metropolis of Metro Manila, the newest Noiph mall in the Philippines has just been completed! The construction manager, Penchick, ordered a state-of-the-art monument to be built with nn pillars.

The heights of the monument's pillars can be represented as an array hh of nn positive integers, where hih_i represents the height of the ii-th pillar for all ii between 11 and nn.

Penchick wants the heights of the pillars to be in non-decreasing order, i.e. hihi+1h_i \le h_{i + 1} for all ii between 11 and n1n - 1. However, due to confusion, the monument was built such that the heights of the pillars are in non-increasing order instead, i.e. hihi+1h_i \ge h_{i + 1} for all ii between 11 and n1n - 1.

Luckily, Penchick can modify the monument and do the following operation on the pillars as many times as necessary:

  • Modify the height of a pillar to any positive integer. Formally, choose an index 1in1\le i\le n and a positive integer xx. Then, assign hi:=xh_i := x.

Help Penchick determine the minimum number of operations needed to make the heights of the monument's pillars non-decreasing.

Input

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

The first line of each test case contains a single integer nn (1n501 \leq n \leq 50) — the number of pillars.

The second line of each test case contains nn integers h1,h2,,hnh_1, h_2, \ldots, h_n (1hin1 \le h_i \le n and hihi+1h_i\ge h_{i+1}) — the height of the pillars.

Please take note that the given array hh is non-increasing.

Note that there are no constraints on the sum of nn over all test cases.

Output

For each test case, output a single integer representing the minimum number of operations needed to make the heights of the pillars non-decreasing.

Note

In the first test case, the initial heights of pillars are h=[5,4,3,2,1]h = [5, 4, 3, 2, 1].

  • In the first operation, Penchick changes the height of pillar 11 to h1:=2h_1 := 2.
  • In the second operation, he changes the height of pillar 22 to h2:=2h_2 := 2.
  • In the third operation, he changes the height of pillar 44 to h4:=4h_4 := 4.
  • In the fourth operation, he changes the height of pillar 55 to h5:=4h_5 := 4.

After the operation, the heights of the pillars are h=[2,2,3,4,4]h = [2, 2, 3, 4, 4], which is non-decreasing. It can be proven that it is not possible for Penchick to make the heights of the pillars non-decreasing in fewer than 44 operations.

In the second test case, Penchick can make the heights of the pillars non-decreasing by modifying the height of pillar 33 to h3:=2h_3 := 2.

In the third test case, the heights of pillars are already non-decreasing, so no operations are required.

Samples

3
5
5 4 3 2 1
3
2 2 1
1
1
4
1
0

在线编程 IDE

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