K Nearest Values
Print the K values closest to X, in ascending order. Break distance ties by preferring the SMALLER value.
Input: the first line has N, K and X; the second line has N integers.
Output: the K chosen values, ascending.
Constraints:
- 1 ≤ K ≤ N ≤ 105
- |values|, |X| ≤ 106
Sample Tests
Input 1
5 3 4 1 2 3 7 9
Output 1
1 2 3
Input 2
2 1 5 4 6
Output 2
4
Discussion (opens after you solve — no spoilers before)
No comments yet.