#P1138. Find the kth Smallest Distinct Number
Find the kth Smallest Distinct Number
Find the kth Smallest Distinct Number
You are given (n) positive integers. Your task is to find the (k)-th smallest distinct integer among them. That is, first remove duplicates from the list, sort the remaining integers in non-decreasing order, and then output the (k)-th element (1-indexed). If there are fewer than (k) distinct integers, output (-1).
Formally, given a list (A = [a_1, a_2, \dots, a_n]), let (D = {a_i : 1 \leq i \leq n}) be the set of unique integers. Sort (D) in ascending order and find the element at index (k) (1-indexed).
inputFormat
The first line of the input contains two space-separated integers (n) and (k).
The second line contains (n) space-separated positive integers (a_1, a_2, \dots, a_n).
outputFormat
Output a single integer, which is the (k)-th smallest distinct number. If (k) is greater than the number of distinct integers, output (-1).
sample
6 3
1 2 3 4 5 6
3