#C13147. K-th Smallest Element
K-th Smallest Element
K-th Smallest Element
Given an unsorted list of integers and an integer \( k \), find the \( k \)th smallest element in the list.
If \( k \) is less than 1 or greater than the number of elements \( n \) (i.e., if \( k \notin [1, n] \)), then output an error message: k is out of bounds
.
For example, if the list is [7, 10, 4, 3, 20, 15] and \( k = 3 \), the 3rd smallest element is 7.
inputFormat
The input is read from standard input (stdin) and has the following format: The first line contains an integer ( n ), the number of elements in the list. The second line contains ( n ) space-separated integers representing the list. The third line contains an integer ( k ), representing the order of the smallest element to find.
outputFormat
Print the ( k )th smallest element to standard output (stdout). If ( k ) is out of bounds, print exactly: "k is out of bounds".## sample
6
7 10 4 3 20 15
3
7