A grading system stores the scores of n lab submissions. Scores may repeat. Given an integer k, report the k-th largest score, where duplicates are counted by position: if the scores sorted in non-increasing order are s[1] >= s[2] >= ... >= s[n], the answer is s[k].
Line 1: two integers n and k.
Line 2: n space-separated integers, the scores.
A single integer: the k-th largest score.
Example 1
Input
5 2 30 10 50 40 20
Expected
40
Explanation
Sorted non-increasing: 50 40 30 20 10. The 2nd largest is 40.
Example 2
Input
3 3 7 7 7
Expected
7
Explanation
All three scores are 7, so the 3rd largest is also 7.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →