#K85777. Longest Interesting Subsequence

    ID: 36717 Type: Default 1000ms 256MiB

Longest Interesting Subsequence

Longest Interesting Subsequence

You are given an array of n integers and a requirement value k. An "interesting" subsequence is defined as a subsequence consisting of distinct integers with a length of at least \( k \). Your task is to determine, for each test case, the length of the longest possible interesting subsequence. In other words, if the set of distinct numbers in the array has at least \( k \) elements, output the total count of distinct numbers; otherwise, output \(-1\).

Note: The subsequence does not need to be contiguous.

inputFormat

The first line of input contains a single integer \( t \) representing the number of test cases. For each test case, the first line contains two space-separated integers \( n \) and \( k \), where \( n \) is the length of the array and \( k \) is the minimum required length for an interesting subsequence. The next line contains \( n \) space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line containing one integer. The integer is the length of the longest interesting subsequence if it exists; otherwise, output \(-1\).

## sample
3
6 3
1 2 2 3 4 5
5 4
1 1 1 1 1
7 5
2 4 3 2 5 6 2
5

-1 5

</p>