Codeforces Round 1070 (Div. 2)
A
Operations with Inversions
Codeforces
800
原题
←B →
翻译中…

Given an array $a_1, a_2, \ldots, a_n$. In one operation, you can choose a pair of indices $i, j$ such that $1 \le i \lt j \le n$, $a_i \gt a_j$, and remove the element at index $j$ from the array. After that, the size of the array will decrease by $1$, and the relative order of the elements will not change.

翻译中…

Determine the maximum number of operations that can be performed on the array if they are applied optimally.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains an integer $n$ ($1 \le n \le 100$) — the size of the initial array.

翻译中…

The second line of each test case contains $n$ natural numbers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$).

翻译中…

Output

翻译中…

For each test case, output the maximum number of operations that you can perform on the given array.

翻译中…

Note

翻译中…

In the first example, we can first choose the pair $i = 2$, $j = 3$ with values $a_2 = 2$, $a_3 = 1$ and remove $a_3$. The resulting array will be $a = [3, 2]$. After that, we can remove the second element by choosing the pair $i = 1$, $j = 2$. The total number of operations is $2$.

翻译中…

In the second, third, and fifth examples, no operations can be performed since there are no suitable pairs.

翻译中…

In the fourth example, we can remove the second and fifth elements. It can be shown that this is the optimal answer and there is no solution that removes more elements.

翻译中…

样例

Input #1
5
3
3 2 1
3
1 2 3
3
3 3 3
5
3 1 4 5 2
1
1
Output #1
2
0
0
2
0
InputCopy OutputCopy
题目信息
题号
2176A
时间限制
1 s
内存限制
256 MB
标签
贪心
模拟
数学

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