#C10538. K-th Largest Element

    ID: 39754 Type: Default 1000ms 256MiB

K-th Largest Element

K-th Largest Element

Given an array of n integers, your task is to find the k-th largest element in the array. The k-th largest element is defined as the element that would appear in the k-th position if the array was sorted in descending order. This problem can be solved efficiently using a min-heap data structure.

Note: All formulas, if any, should be written in \(\LaTeX\) format. For example, if you need to describe the k-th largest element, you may mention it as the element at position \( k \) in the sorted order.

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\) represents the order (1-indexed) of the largest element to find.
  • The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

Output a single integer to standard output (stdout) which is the k-th largest element in the array.

## sample
5 2
3 2 1 5 6
5