#C6820. K-th Largest Element in an Array
K-th Largest Element in an Array
K-th Largest Element in an Array
Given an array of integers and an integer k, find the k-th largest element in the array. Formally, if the array is sorted in non-increasing order as \(a_1 \ge a_2 \ge \cdots \ge a_n\), your task is to output \(a_k\). This problem is fundamental in understanding selection algorithms and sorting techniques.
Note: The array can contain duplicate elements, and \(k\) is guaranteed to be valid (i.e., \(1 \le k \le n\), where \(n\) is the number of elements in the array).
inputFormat
The input consists of two lines:
- The first line contains space-separated integers representing the elements of the array.
- The second line contains a single integer \(k\), which specifies the position of the largest element to find.
You should read the input from standard input (stdin).
outputFormat
Output a single integer: the k-th largest element in the array, printed to standard output (stdout).
## sample3 2 1 5 6 4
2
5