AmazonOA #43
Medians
估计简单可在线判题
Choose any order-preserving subsequence of length k, sort it, and take its ⌈k/2⌉-th element as the median (for even lengths, the smaller middle value is taken, consistent with the source examples). Output the largest and the smallest median over all choices.
输入格式
The first line contains n k (1≤k≤n≤100000), and the second line contains n values (0..10⁹).
输出格式
Output the maximum median and the minimum median.
样例 1
输入:
3 2
1 2 3
输出:
2 1
样例 2
输入:
1 1
9
输出:
9 9
样例 3
输入:
5 3
1 2 3 4 5
输出:
4 2
样例说明
Example 1: the median is the smaller of the two chosen items; choosing [2,3] gives the maximum 2, and choosing [1,2] gives the minimum 1. Example 2: there is only 9, so both answers are 9. Example 3: the largest three items [3,4,5] have median 4, and the smallest three items [1,2,3] have median 2.