#K83417. Smallest Deque Sequence
Smallest Deque Sequence
Smallest Deque Sequence
You are given a number of queries. For each query, you are provided with two integers (N) and (M), and an array (X) of (N) integers. The task is to construct the lexicographically smallest sequence (or deque) of length (M) by selecting the (M) smallest numbers from the array. Formally, for each query, sort the array (X) in non-decreasing order and output the first (M) elements of the sorted array.
Input Format: The input is read from standard input (stdin). The first line contains an integer (Q), the number of queries. For each query, the first line contains two integers (N) and (M). The next line contains (N) space-separated integers representing the array (X).
Output Format: For each query, output a single line with (M) space-separated integers representing the smallest lexicographical sequence.
Note: Use the following relation in your solution if needed: (\text{Result} = \text{sorted}(X)[0:M]).
inputFormat
The first line contains an integer (Q) that denotes the number of queries. Then, for each query, there are two lines:
1. The first line contains two integers (N) and (M) where (N) is the length of the array and (M) is the number of elements to select.
2. The second line contains (N) space-separated integers, representing the array (X).
outputFormat
For each query, output a single line containing (M) integers, separated by a space, representing the lexicographically smallest sequence constructed by selecting the (M) smallest integers from the sorted array (X). The output should be written to standard output (stdout).## sample
3
5 3
4 3 2 7 1
4 2
6 3 8 4
3 1
2 1 3
1 2 3
3 4
1
</p>