Codeforces Round 987 (Div. 2) |
---|
Finished |
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 $$$n$$$ pillars.
The heights of the monument's pillars can be represented as an array $$$h$$$ of $$$n$$$ positive integers, where $$$h_i$$$ represents the height of the $$$i$$$-th pillar for all $$$i$$$ between $$$1$$$ and $$$n$$$.
Penchick wants the heights of the pillars to be in non-decreasing order, i.e. $$$h_i \le h_{i + 1}$$$ for all $$$i$$$ between $$$1$$$ and $$$n - 1$$$. However, due to confusion, the monument was built such that the heights of the pillars are in non-increasing order instead, i.e. $$$h_i \ge h_{i + 1}$$$ for all $$$i$$$ between $$$1$$$ and $$$n - 1$$$.
Luckily, Penchick can modify the monument and do the following operation on the pillars as many times as necessary:
Help Penchick determine the minimum number of operations needed to make the heights of the monument's pillars non-decreasing.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of pillars.
The second line of each test case contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_n$$$ ($$$1 \le h_i \le n$$$ and $$$h_i\ge h_{i+1}$$$) — the height of the pillars.
Please take note that the given array $$$h$$$ is non-increasing.
Note that there are no constraints on the sum of $$$n$$$ over all test cases.
For each test case, output a single integer representing the minimum number of operations needed to make the heights of the pillars non-decreasing.
355 4 3 2 132 2 111
4 1 0
In the first test case, the initial heights of pillars are $$$h = [5, 4, 3, 2, 1]$$$.
After the operation, the heights of the pillars are $$$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 $$$4$$$ operations.
In the second test case, Penchick can make the heights of the pillars non-decreasing by modifying the height of pillar $$$3$$$ to $$$h_3 := 2$$$.
In the third test case, the heights of pillars are already non-decreasing, so no operations are required.
Name |
---|