#149Hard
K-th order statistic
Time: 2 s · Memory: 256 MB
- Sorting
Statement
An array of numbers is given by a generator: , and for . Find the number at position after sorting the array in increasing order (positions start from ).
Input format
A single line with six integers: , , , , , (, , ).
Output format
A single number — the -th order statistic.
Examples
Input
5 2 3 2 1 10
Output
3
Input
6 6 1 1 1 100
Output
6
Note
A full sort is , but when only one position is needed, quickselect runs in on average: partition the array around a random pivot and continue only in the part that contains position . In C++ this is std::nth_element.
reaches — multiply in a 64-bit type. In the first example the array is , sorted , and the answer is .
