#P14197. [ICPC 2024 Hangzhou R] Kind of Bingo
[ICPC 2024 Hangzhou R] Kind of Bingo
题目描述
There is a grid with rows and columns. The cells in the grid are numbered from to , where the cell on the -th row and the -th column is numbered as .
Given a permutation of , we're going to perform operations according to the permutation. For the -th operation, we'll mark cell . If after the -th operation, there is at least one row such that all the cells in that row are marked, and is as small as possible, then we say is the bingo integer of the permutation.
You're given the chance to modify the permutation at most times (including zero times). Each time you can swap a pair of elements in the permutation. Calculate the smallest possible bingo integer after the modifications.
Recall that a sequence of length is a permutation of if and only if each integer from to (both inclusive) appears exactly once in the sequence.
输入格式
There are multiple test cases. The first line of the input contains an integer () indicating the number of test cases. For each test case:
The first line contains three integers , and (, , ), indicating the number of rows and columns of the grid and the number of modifications you can perform.
The second line contains distinct integers ().
It's guaranteed that the sum of of all test cases will not exceed .
输出格式
For each test case output one line containing one integer indicating the smallest possible bingo integer after the modifications.
3
3 5 2
1 4 13 6 8 11 14 2 7 10 3 15 9 5 12
2 3 0
1 6 4 3 5 2
2 3 1000000000
1 2 3 4 5 6
7
5
3
提示
For the first sample test case, we can first swap and , then swap and to get the sequence $[15, 4, 13, 12, 8, 11, 14, 2, 7, 10, 3, 1, 9, 5, 6]$. It's easy to see that after the -th operation, all cells in the -rd row will be marked.
For the second sample test case, it's easy to see that after the -th operation, all cells in the -nd row will be marked.
For the third sample test case, we don't need to make any modifications. It's easy to see that after the -rd operation, all cells in the -st row will be marked.