#C4261. Find the K-th Largest Element

    ID: 47780 Type: Default 1000ms 256MiB

Find the K-th Largest Element

Find the K-th Largest Element

In this problem, you are given a list of integers and a positive integer ( k ). Your task is to find the ( k )-th largest element in the list. More formally, if the elements are sorted in descending order, you need to output the element at position ( k ).

For example, if the list is [3, 2, 1, 5, 6, 4, 8, 7, 9, 10] and ( k = 3 ), then after sorting the list in descending order, it becomes [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] and the 3rd largest element is 8.

This problem involves the usage of data structures such as heaps or sorting algorithms. You are encouraged to implement an efficient solution that can easily handle large inputs.

inputFormat

The input is given via standard input (stdin).

The first line contains two positive integers ( n ) and ( k ), where ( n ) is the number of elements in the list, and ( k ) is the position (when the list is sorted in descending order) of the element to retrieve.

The second line contains ( n ) space-separated integers.

outputFormat

Output the ( k )-th largest element in the list to standard output (stdout).## sample

10 3
3 2 1 5 6 4 8 7 9 10
8