Find K Smallest Distinct Elements
Given a list of N integers, find the K smallest distinct elements. If there are fewer than K distinct elements, output all distinct elements in increasing order. The output should be sorted in increasing order. Use a tie-breaking rule such that if multiple elements could be the K-th smallest, any one of them is acceptable.
Input
The first line contains two integers N and K, separated by a space. The second line contains N integers, separated by spaces.
Output
Print K (or fewer, if not enough distinct elements exist) integers in increasing order, separated by spaces.
Constraints
1 <= N <= 200000, 1 <= K <= N. Each integer is between -10^9 and 10^9.
Example 1
5 3 10 5 20 5 10
5 10 20
The distinct elements are 10, 5, 20. The 3 smallest are 5, 10, 20.
Example 2
7 2 1 1 1 1 1 1 1
1
There is only 1 distinct element (1). Since K=2, we output all distinct elements: 1.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 3 10 5 20 5 10
7 2 1 1 1 1 1 1 1