Codeforces Round 987 (Div. 2)
A
Penchick and Modern Monument
Codeforces
800
原题
←B →
翻译中…

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:

翻译中…
  • Modify the height of a pillar to any positive integer. Formally, choose an index $1\le i\le n$ and a positive integer $x$. Then, assign $h_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 $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.

翻译中…

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]$.

翻译中…
  • In the first operation, Penchick changes the height of pillar $1$ to $h_1 := 2$.
  • In the second operation, he changes the height of pillar $2$ to $h_2 := 2$.
  • In the third operation, he changes the height of pillar $4$ to $h_4 := 4$.
  • In the fourth operation, he changes the height of pillar $5$ to $h_5 := 4$.
翻译中…

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.

翻译中…

样例

Input #1
3
5
5 4 3 2 1
3
2 2 1
1
1
Output #1
4
1
0
InputCopy OutputCopy
题目信息
题号
2031A
时间限制
1 s
内存限制
256 MB
标签
构造
动态规划
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。