#K80497. Merge K Sorted Arrays
Merge K Sorted Arrays
Merge K Sorted Arrays
You are given t test cases. In each test case, you have k sorted arrays. The first number of each array line indicates the number of elements in that array followed by the elements themselves in sorted order.
Your task is to merge the k sorted arrays into one single sorted list and output it as a space-separated sequence.
For example, consider a test case with 3 arrays:
3 1 4 5 5 2 2 7 10 15 4 1 3 4 8These correspond to arrays: [1, 4, 5], [2, 2, 7, 10, 15], and [1, 3, 4, 8]. The merged sorted list is:
$$1\ 1\ 2\ 2\ 3\ 4\ 4\ 5\ 7\ 8\ 10\ 15$$
inputFormat
The input is given via standard input (stdin) and has the following structure:
- The first line contains an integer t representing the number of test cases.
- For each test case:
- The first line contains an integer k, the number of sorted arrays.
- The following k lines each start with an integer n (the number of elements in the array) followed by n integers in non-decreasing order.
outputFormat
For each test case, output a single line containing the merged sorted sequence with the numbers separated by a single space.
## sample3
3
3 1 4 5
5 2 2 7 10 15
4 1 3 4 8
2
2 0 1
3 -10 5 20
2
4 1 2 3 4
3 2 3 5
1 1 2 2 3 4 4 5 7 8 10 15
-10 0 1 5 20
1 2 2 3 3 4 5
</p>