#K91052. K-th Largest Element Finder

    ID: 37889 Type: Default 1000ms 256MiB

K-th Largest Element Finder

K-th Largest Element Finder

Given an array \( A \) of \( n \) integers and an integer \( k \), your task is to find the \( k \)-th largest element in the array. If \( k > n \), or if any element is not a valid integer, output "Invalid input".

The solution involves sorting the array in descending order and then picking the element at position \( k \) (1-indexed). Formally, if the sorted array is \( A' \), you should output \( A'[k-1] \). If the input fails to meet the criteria, output Invalid input.

inputFormat

The input is provided via standard input (stdin) in the following format:

  1. The first line contains an integer \( n \), representing the number of elements in the array.
  2. The second line contains \( n \) space-separated tokens, each intended to be an integer.
  3. The third line contains an integer \( k \), specifying which largest element to output.

outputFormat

Output via standard output (stdout) a single line containing the \( k \)-th largest element if the input is valid. Otherwise, output Invalid input.

## sample
5
3 1 5 8 2
2
5

</p>