Codeforces Round 1021 (Div. 2)
B
Sasha and the Apartment Purchase
Codeforces
1400
原题
← AC →
翻译中…

Sasha wants to buy an apartment on a street where the houses are numbered from $1$ to $10^9$ from left to right.

翻译中…

There are $n$ bars on this street, located in houses with numbers $a_1, a_2, \ldots, a_n$. Note that there might be multiple bars in the same house, and in this case, these bars are considered distinct.

翻译中…

Sasha is afraid that by the time he buys the apartment, some bars may close, but no more than $k$ bars can close.

翻译中…

For any house with number $x$, define $f(x)$ as the sum of $|x - y|$ over all open bars $y$ (that is, after closing some bars).

翻译中…

Sasha can potentially buy an apartment in a house with number $x$ (where $1 \le x \le 10^9$) if and only if it is possible to close at most $k$ bars so that after that $f(x)$ becomes minimal among all houses.

翻译中…

Determine how many different houses Sasha can potentially buy an apartment in.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1 \leq n \leq 10^5, 0 \leq k \lt n$) — the number of bars and the maximum number of bars that can close.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the house numbers where the bars are located.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of houses where Sasha can buy an apartment.

翻译中…

Note

翻译中…

In the first test case, none of the bars can close, so only houses numbered $2$ and $3$ are suitable. For the house numbered $2$, the sum of distances is $|2 - 1| + |2 - 2| + |2 - 3| + |2 - 4| = 4$, and for the house numbered $3$, the sum of distances is $|3 - 1| + |3 - 2| + |3 - 3| + |3 - 4| = 4$. However, for the house numbered $1$, the sum of distances will be $|1 - 1| + |1 - 2| + |1 - 3| + |1 - 4| = 6$, so the house numbered $1$ is not suitable. It can also be proven that Sasha cannot buy apartments in other houses.

翻译中…

In the second test case, the suitable houses are numbered $6$ and $7$. For Sasha to choose the house numbered $6$, it is sufficient that none of the bars close. For Sasha to choose the house numbered $7$, the bars in houses $1$ and $6$ can close. Then the bars will be located in houses numbered $6$, $7$, and $7$.

翻译中…

样例

Input #1
4
4 0
1 2 3 4
5 2
7 6 6 7 1
3 1
6 7 9
6 2
5 1 9 10 13 2
Output #1
2
2
4
9
InputCopy OutputCopy
题目信息
题号
2098B
时间限制
1 s
内存限制
256 MB
标签
数学
排序

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