#C3547. Find the K-th Largest Element
Find the K-th Largest Element
Find the K-th Largest Element
You are given a list of distinct integers and an integer k. Your task is to find the k-th largest element in the list. The k-th largest element is defined as the element that would be at index k-1
if the array were sorted in descending order. In mathematical notation, if the sorted array is \(A_{sorted}\), then you need to output \(A_{sorted}[k-1]\).
Note: It is guaranteed that 1 ≤ k ≤ n, where n is the number of elements in the list.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer
n
, the number of elements in the list. - The second line contains
n
space-separated integers representing the list. - The third line contains an integer
k
which denotes the k-th largest element to find.
outputFormat
Output the k-th largest element as an integer to standard output (stdout).
## sample6
3 2 1 5 6 4
2
5