K Smallest Elements
Easyjavapythonccppjavascript
Given an integer array and K, find the K smallest values.
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the K smallest values in increasing order, separated by single spaces.
Example 1
Input
6 3 3 1 5 12 2 11
Output
1 2 3
Explanation: The three smallest values are 1, 2 and 3.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000