#C12290. K-th Smallest Element

    ID: 41701 Type: Default 1000ms 256MiB

K-th Smallest Element

K-th Smallest Element

Given an unsorted array of integers, your task is to find the k-th smallest element in the array. If k is greater than the number of elements in the array, output the exact error message "Error: k is greater than the length of the array".

Note: The array is not necessarily sorted and may contain duplicate values. The answer should be determined by considering the sorted order of the array (in non-decreasing order).

The formula for the index in a sorted array (0-indexed) is given by: \( index = k - 1 \).

inputFormat

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

  1. The first line contains a single integer n, the number of elements in the array.
  2. The second line contains n space-separated integers representing the array elements.
  3. The third line contains a single integer k, indicating which smallest element to find.

outputFormat

Output the k-th smallest element to standard output (stdout). If k is greater than the length of the array, output exactly "Error: k is greater than the length of the array".

## sample
6
3 2 1 5 6 4
2
2