#K71262. K-th Largest Element Finder
K-th Largest Element Finder
K-th Largest Element Finder
This problem asks you to find the \(k\)-th largest element in an array of integers. You are given an integer \(n\) representing the number of elements, followed by \(n\) integers, and then an integer \(k\). Your task is to output the \(k\)-th largest element in the array. If \(k\) is greater than \(n\), output -1.
For example, for the array [3, 2, 1, 5, 6, 4] with \(k = 2\), the answer is 5.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (n) (the number of elements in the array). The second line contains (n) space-separated integers. The third line contains an integer (k), representing which largest element to find.
outputFormat
Output a single integer on standard output (stdout) which is the (k)-th largest element of the array. If (k) is greater than (n), output -1.## sample
6
3 2 1 5 6 4
2
5