Merge K Sorted Arrays

Hard

You are given k sorted arrays in the form of 2D integer matrix arr of size k*n.
Merge them into a single sorted array.

Testing

Input Format

The first line contains two space-separated integers k and n.

The next k lines have n space-separated integers each denoting the elements of the array.

Output Format

Space-separated results of the resultant sorted array.

Sample Input

3 4
1 3 7 10
3 3 6 8
2 4 7 9

Expected Output

1 2 3 3 3 4 6 7 7 8 9 10

1 <= k,n <= 500
-109 <= arrij <= 109

Editorial Link: Editorial