#C8537. Find the K-th Smallest Element
Find the K-th Smallest Element
Find the K-th Smallest Element
Given an unsorted array of n integers, your task is to find the k-th smallest element in the array. In other words, if the array were sorted in non-decreasing order, you need to output the element that appears in the k-th position.
Note: It is guaranteed that \(1 \leq k \leq n\). You may use any efficient algorithm such as a heap-based approach or sorting.
Input: The input is read from standard input.
Output: Print the k-th smallest element to standard output.
Mathematically, if the sorted array is \(a_1, a_2, \dots, a_n\), then the answer is \(a_k\).
inputFormat
The first line contains two space-separated integers (n) and (k), where (n) is the number of elements in the array and (k) is the order of the smallest element to find. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
Output a single integer, the k-th smallest element in the array.## sample
10 4
7 10 4 3 20 15 1 2 9 8
4