#K86197. K-th Smallest Element

    ID: 36811 Type: Default 1000ms 256MiB

K-th Smallest Element

K-th Smallest Element

Given an unsorted array of n integers and an integer k, your task is to determine the k-th smallest element in the array. Formally, if the array is sorted in non-decreasing order, you must output the element at position k (using 1-based indexing).

You are guaranteed that \(1 \leq k \leq n\). The array may contain duplicate elements.

Example: For the input array [7, 10, 4, 3, 20, 15] with n = 6 and k = 3, the sorted order is [3, 4, 7, 10, 15, 20] and the answer is 7.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains two integers, n and k, separated by a space, where n is the number of elements in the array and k is the position (1-indexed) of the element to find.
  2. The second line contains n integers separated by spaces, representing the elements of the array.

outputFormat

Output a single integer to standard output (stdout) which is the k-th smallest element in the array.

## sample
6 3
7 10 4 3 20 15
7

</p>