#K83347. Merge Sorted Lists

    ID: 36177 Type: Default 1000ms 256MiB

Merge Sorted Lists

Merge Sorted Lists

You are given two lists of integers, each of which is sorted in non-decreasing order. Your task is to merge these two lists into a single sorted list while preserving the order.

The two lists will be provided as input on two separate lines. Each line will contain zero or more space-separated integers. An empty line indicates an empty list.

For example, if the input is:

3 8 15 22
7 9 10 33

Then the output should be:

3 7 8 9 10 15 22 33

Note: The merging process is similar to the one used in Merge Sort. In terms of algorithmic complexity, merging two sorted lists takes \(O(n+m)\) time, where \(n\) and \(m\) denote the lengths of the two lists.

inputFormat

The input consists of two lines:

  • The first line contains the elements of the first sorted list, separated by spaces. It may be an empty line denoting an empty list.
  • The second line contains the elements of the second sorted list, also separated by spaces. It too could be empty.

All elements are integers.

outputFormat

Output a single line containing the merged sorted list. The numbers should be output in non-decreasing order, separated by a single space. If both lists are empty, print an empty line.

## sample
3 8 15 22
7 9 10 33
3 7 8 9 10 15 22 33