#K7821. Find the k-th Largest Element

    ID: 35036 Type: Default 1000ms 256MiB

Find the k-th Largest Element

Find the k-th Largest Element

Given an array of non-negative integers and an integer k, the goal is to determine the k-th largest element in the array. The array might contain duplicate values and is not necessarily sorted.

Note: The k-th largest element is the element that would appear in that position if the array were sorted in descending order. Formally, if the sorted array is (a_1 \ge a_2 \ge \ldots \ge a_n), then the answer is (a_k).

inputFormat

The input is read from standard input (stdin) and consists of two lines.

The first line contains two space-separated integers, (n) and (k), where (n) is the number of elements in the array and (k) is the position of the largest element to find.

The second line contains (n) space-separated non-negative integers representing the elements of the array.

outputFormat

Output a single integer to standard output (stdout): the k-th largest element in the array.## sample

6 2
3 2 1 5 6 4
5