#K77032. Find the K-th Largest Element
Find the K-th Largest Element
Find the K-th Largest Element
You are given an integer array of size \(n\) and an integer \(k\). Your task is to find the \(k\)-th largest element in the array. Note that the \(k\)-th largest element refers to the element that would be in position \(k\) if the array were sorted in descending order. This is not the same as the \(k\)-th distinct element.
Input Format: The first line contains two integers \(n\) and \(k\). The second line contains \(n\) space-separated integers representing the array elements.
Output Format: Output a single integer denoting the \(k\)-th largest element.
For example, if the array is [3, 2, 1, 5, 6, 4] and \(k = 2\), the sorted array in descending order is [6, 5, 4, 3, 2, 1] and the 2nd largest element is 5.
inputFormat
The input is read from standard input (stdin) and is structured as follows:
- The first line contains two space-separated integers \(n\) (the number of elements) and \(k\).
- The second line contains \(n\) space-separated integers representing the array.
outputFormat
Output a single integer to stdout which is the \(k\)-th largest element of the array.
## sample6 2
3 2 1 5 6 4
5