All tasks
Hardsortingarrays

Kth Largest Element

Time limit 2 s · Memory 64 MBAcceptance: 100.0%Solved by: 1

Statement

The first line contains n, the second line contains n integers, the third line contains k. Print the element that stands at position k when the array is sorted in descending order (duplicates count separately).

Examples

Example 1
Input
6
3 2 1 5 6 4
2
Output
5
Example 2
Input
9
3 2 3 1 2 4 5 5 6
4
Output
4

Constraints

  • 1 ≤ k ≤ n ≤ 10^5
  • -10^9 ≤ a_i ≤ 10^9
Solve this task to unlock the editorial.

AI tutor

Stuck? Get a nudge — the tutor explains the idea, it never hands you the solution.