P10922 Happybob's Numbers (UBC001B)
Description
Happybob has $n$ numbers on the ground. The $i$-th number is denoted as $a_i$. Happybob is studying how to delete all of these numbers. Before he starts all operations, he has one chance to rearrange these numbers in any order. Then he will delete numbers in the following way:
- Happybob has a deletion index $h$ (initially $h=1$). He will set a new variable $H$ with value $a_h$, and then for every positive integer $i$ satisfying $h\le i
Input Format
The first line contains a positive integer $t$, the number of test cases.
For each test case:
The first line contains a positive integer $n$, the size of $a$.
The second line contains $n$ positive integers, representing the elements in $a$.
Output Format
Output $t$ lines. Each line contains a positive integer, the answer for the corresponding test case.
Explanation/Hint
#### Sample Explanation
For the first test case, happybob can sort the array $a$ as $[2, 3, 1]$. The deletion process is as follows:
| Operation | $h$ (after the operation) | Numbers on the ground (after the operation) |
| -- | -- | -- |
| Initial | $1$ | $[2, 3, 1]$ |
| $1$ | $2$ | $[3, 1]$ |
| $2$ | $1$ | $[3]$ |
| $3$ | $3$ | $[]$ |
There are no numbers left on the ground, meaning a total of $3$ numbers were deleted.
For the second test case, it can be proven that no matter how you rearrange $a$, you can only delete one number.
#### Constraints
**This problem has multiple test cases.**
For $100\%$ of the testdata, it is guaranteed that $1 \le t,n,\sum n\le 5 \times 10^5$, $1\le a_i\le 10^9$. Here $\sum n$ is the sum of $n$ over all test cases.
Translated by ChatGPT 5