Problems > K-th Smallest

K-th Smallest

Difficulty: 1000 3000 ms 128 MB

sorting

Print the K-th smallest element (duplicates count separately).

Input: the first line has N and K; the second line has N integers.

Output: the K-th smallest value.

Constraints:

  • 1 ≤ K ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
5 2
7 1 5 1 9
Output 1
1
Input 2
1 1
4
Output 2
4

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.