Codeforces Round 1002 (Div. 2)
B
Cost of the Array
Codeforces
1300
原题
← AC →
翻译中…

You are given an array $a$ of length $n$ and an even integer $k$ ($2 \le k \le n$). You need to split the array $a$ into exactly $k$ non-empty subarrays$^{\dagger}$ such that each element of the array $a$ belongs to exactly one subarray.

翻译中…

Next, all subarrays with even indices (second, fourth, $\ldots$, $k$-th) are concatenated into a single array $b$. After that, $0$ is added to the end of the array $b$.

翻译中…

The cost of the array $b$ is defined as the minimum index $i$ such that $b_i \neq i$. For example, the cost of the array $b = [1, 2, 4, 5, 0]$ is $3$, since $b_1 = 1$, $b_2 = 2$, and $b_3 \neq 3$. Determine the minimum cost of the array $b$ that can be obtained with an optimal partitioning of the array $a$ into subarrays.

翻译中…

$^{\dagger}$An array $x$ is a subarray of an array $y$ if $x$ can be obtained from $y$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($2 \le k \le n \le 2 \cdot 10^5$, $k$ is even) — the length of the array $a$ and the number of subarrays.

翻译中…

The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array $a$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer — the minimum cost of the array $b$ that can be obtained.

翻译中…

Note

翻译中…

In the first test case, there are only two possible partitionings: $[[1], [1, 1]]$ and $[[1, 1], [1]]$. In either case, $b_1 = 1$, and $b_2 \ne 2$, so the cost is $2$.

翻译中…

In the second test case, there is only one possible partitioning, where $b = [1, 2, 3, 4, 0]$, so the cost is $5$ ($b_5 = 0 \ne 5$).

翻译中…

In the third test case, the following partitioning works: $[[1], [1, 1], [2], [2]]$. Then $b = [1, 1, 2, 0]$, and the cost is $2$.

翻译中…

样例

Input #1
4
3 2
1 1 1
8 8
1 1 2 2 3 3 4 4
5 4
1 1 1 2 2
5 4
1 1 1000000000 2 2
Output #1
2
5
2
1
InputCopy OutputCopy
题目信息
题号
2059B
时间限制
1 s
内存限制
256 MB
标签
暴力
构造
贪心
数学

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