← 返回 meta 的题目列表Merge M Sorted Arrays and Output First K Elements
类型:online_judge
Coding: Merge M Sorted Arrays and Output the First K Elements
Given m non-decreasing integer sequences, output the first K elements of the merged sorted order across all sequences (keep duplicates).
Input
First line: m K
Next m lines: len_i followed by len_i integers (already sorted non-decreasing within each sequence)
Output
One line: the first K elements separated by spaces.
If the total number of elements is less than K, output all elements.
Constraints (typical)
1 <= m <= 1e5
Total elements N = sum(len_i)
1 <= K <= min(N, 2e5) (or as specified)
Example
Input:
3 5
3 1 4 10
3 2 3 9
2 0 7
Output:
0 1 2 3 4
Example
Input
3 5
3 1 4 10
3 2 3 9
2 0 7
Output
0 1 2 3 4