#C1213. Find the K-th Largest Element
Find the K-th Largest Element
Find the K-th Largest Element
Given an array of n integers and an integer k, find the k-th largest element in the array. The k-th largest element is the element that would be at position k if the array were sorted in descending order.
For example, if the input array is [3, 2, 1, 5, 6, 4] and k = 2, the second largest element is 5.
Note: You are required to implement an efficient solution. A possible approach is to maintain a min-heap of size k. The algorithm has a time complexity of \(O(n \log k)\), where \(n\) is the number of elements in the array.
inputFormat
The first line of input contains two integers n and k, where n is the number of elements in the array and k is the position (1-indexed) of the largest element to find.
The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output a single integer, which is the k-th largest element in the array.
## sample6 2
3 2 1 5 6 4
5
</p>