#K2976. Kth Largest Element Problem
Kth Largest Element Problem
Kth Largest Element Problem
You are given an array of N integers and an integer K. Your task is to find the Kth largest element in the array. In other words, when the array is sorted in descending order, you should return the element that appears in the Kth position.
Note: It is guaranteed that K is between 1 and N (inclusive). Efficient algorithms are required to handle large input sizes.
Mathematically, if the sorted array in descending order is given by \(a_1 \ge a_2 \ge \dots \ge a_N\), then you need to find \(a_K\).
inputFormat
The input is given via stdin
as follows:
- The first line contains two integers N and K separated by a space.
- The second line contains N space-separated integers representing the array.
outputFormat
Output a single integer to stdout
which is the Kth largest element in the array.
6 2
3 2 1 5 6 4
5