#K6006. Find K-th Largest Element

    ID: 31002 Type: Default 1000ms 256MiB

Find K-th Largest Element

Find K-th Largest Element

You are given an array of integers along with an integer k. Your task is to find the k-th largest element in the array.

This problem requires you to efficiently sort or partially sort the array and then retrieve the element that ranks as the k-th largest. For instance, if the array is \( [3, 2, 1, 5, 6, 4] \) and \( k = 2 \), the answer is \( 5 \) because it is the second largest element.

The input is provided via standard input and the result should be printed to standard output.

inputFormat

The first line contains two integers: n (the number of elements in the array) and k.

The second line contains n space-separated integers which represent the array.

\( \textbf{Input Format:} \)
\( n\ k \)
\( a_1\ a_2\ \ldots\ a_n \)

outputFormat

Output a single integer which is the k-th largest element in the given array.

\( \textbf{Output Format:} \)
\( answer \)

## sample
6 2
3 2 1 5 6 4
5