#C10647. Merging Sorted Pages
Merging Sorted Pages
Merging Sorted Pages
You are given several pages containing sorted survey responses. Each page starts with an integer k, representing the number of responses on that page, followed by k integers in sorted order. Your task is to merge all the responses from all pages into a single sorted list.
Input: The first line contains an integer N that represents the number of pages. The following N lines each describe a page. Each page starts with an integer k (which could be zero), followed by k integers. All integers in a page are given in increasing order.
Output: Output the merged sorted list of all responses from the pages. The numbers should be separated by a single space.
Note: The merging process should be efficient, and you can assume the total number of responses is not extremely large.
The mathematical concept behind the merging process can be expressed as follows: \[ \text{result} = \bigcup_{i=1}^{N} S_i \quad\text{sorted in non-decreasing order} \]
inputFormat
The input is read from stdin and is formatted as follows:
N k1 a1,1 a1,2 ... a1,k1 k2 a2,1 a2,2 ... a2,k2 ... kN aN,1 aN,2 ... aN,kN
Where N is the number of pages. For each page, the first number k indicates the number of responses on that page, followed by k integers which are in sorted order.
outputFormat
The output is written to stdout and consists of a single line containing all the merged sorted integers separated by a space.
## sample1
3 1 2 3
1 2 3