All problems

Kth Largest Element

mediumPythonArraysSorting

Lakeside Athletics publishes a leaderboard after every meet, and the coach keeps asking the same question in different clothes: who came second, who came fifth, who came last. The scores reach the software in the order the athletes took their attempts, which is no use for ranking, and the coach's question arrives as a bare number.

Task: Print the k-th largest score, counting from 1, so k = 1 asks for the highest score of all.

Input

The first line holds 1 to 1000 integers separated by single spaces -- the scores. The second line holds a single integer k, with 1 <= k <= the number of scores.

Output

One line holding the k-th largest score. Rank is by place in the ranking, not by distinct value: if the two best scores are equal they occupy places 1 and 2, so k = 2 gives that same score again.

Example:

Input:
3 2 1 5 6 4
2

Output:
5

Sign in to solve this problem

Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.

Sign in

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…