#C6160. K-th Smallest Unique Element

    ID: 49890 Type: Default 1000ms 256MiB

K-th Smallest Unique Element

K-th Smallest Unique Element

Given an array of n integers and an integer k, your task is to find the k-th smallest unique integer in the array after removing duplicates. In other words, first remove all duplicate elements, sort the remaining numbers in ascending order, and then select the element at the k-th position (using 1-indexing).

If the array does not contain at least k unique elements, output -1.

Formally, let \(U = \text{sorted}(\{a_1, a_2, \dots, a_n\})\). If \(|U| \geq k\), output \(U[k-1]\), otherwise output \(-1\).

inputFormat

The input is provided via stdin in two lines:

  1. The first line contains two space-separated integers n and k, where n is the number of integers in the array and k is the order of the unique integer to find.
  2. The second line contains n space-separated integers.

outputFormat

Output the k-th smallest unique integer to stdout. If there are fewer than k unique numbers in the array, output -1.

## sample
6 3
3 1 3 2 1 4
3