#K78787. K-th Largest Unique Score
K-th Largest Unique Score
K-th Largest Unique Score
Given a list of integers and an integer k, your task is to find the k-th largest unique score in the list. Formally, let \( A \) be the set of unique elements from the list, and let \( A^* \) be the elements of \( A \) sorted in descending order. You need to output the element at the \( k \)-th position in \( A^* \) (1-indexed). If there are fewer than \( k \) unique scores, output -1
.
For example, consider the list [4, 5, 1, 4, 3, 2, 5, 2] and \( k = 3 \). The unique scores are {1, 2, 3, 4, 5}, which when sorted in descending order become [5, 4, 3, 2, 1]. The 3rd largest element is 3. Therefore, the output is 3.
inputFormat
The input is given from standard input (stdin) and has the following format:
- The first line contains a single integer \( n \) which represents the number of elements in the list.
- The second line contains \( n \) space-separated integers.
- The third line contains an integer \( k \).
outputFormat
Output to standard output (stdout) a single integer: the k-th largest unique score. If there are fewer than \( k \) unique scores, output -1
.
8
4 5 1 4 3 2 5 2
3
3