P17298 [ICPC 2026 Xi'an I] Registration

Description

The ICPC 2026 Chang'an Invitational Tournament is about to begin. There are $n$ teams planning to register for the competition, where the $i$-th team will visit the registration website at the $v_i$-th second. For every positive integer $s$: - If the number of teams visiting the registration website at the $s$-th second is no more than $x$, then all teams visiting at the $s$-th second register successfully. - Otherwise, the registration website crashes at that second due to too many teams visiting, and all teams visiting at the $s$-th second fail to register. As the chief judge of the ICPC 2026 Chang'an Invitational Tournament, Yuki wants to know the registration status of this competition. Therefore, you need to help her calculate the number of teams that successfully register.

Input Format

This problem contains multiple test cases. The first line contains a positive integer $t$ $(1 \le t \le 10^5)$, representing the number of test cases. For each test case: - The first line contains two positive integers $n, x$ $(1 \le n \le 2\cdot10^5,\ 1 \le x \le n)$. - The second line contains $n$ positive integers $v_1, \dots, v_n$ $(1 \le v_i \le 10^9)$. It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.

Output Format

For each test case, output a single line containing an integer representing the number of teams that successfully register.

Explanation/Hint

For the first test case: - At the $1$-st second, teams $1,4,5$ visited the registration website. Since $3 > 2$, the website crashed at this second, and these $3$ teams failed to register. - At the $2$-nd second, team $2$ visited the registration website. Since $1 \le 2$, the website did not crash, and this team registered successfully. - At the $3$-rd second, team $3$ visited the registration website. Since $1 \le 2$, the website did not crash, and this team also registered successfully. - A total of $2$ teams registered successfully, so the answer is $2$. For the second test case: - The website did not crash at any second, all $5$ teams registered successfully, so the answer is $5$. For the third test case: - The website crashed in each of the first $3$ seconds, all $6$ teams failed to register, so the answer is $0$.