#C13576. Merge Sorted Lists
Merge Sorted Lists
Merge Sorted Lists
Given two sorted lists, your task is to merge them into a single sorted list. The merged list should contain all elements from both lists in non-decreasing order.
You need to handle edge cases such as one or both input lists being empty. The merging process must be implemented efficiently by maintaining the order of the input lists.
In mathematical terms, if the two input sorted lists are \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\), then the output should be the sorted list \(C\) satisfying \(C = A \cup B\) with all elements in ascending order.
inputFormat
The input consists of two lines read from standard input:
- The first line contains space-separated integers representing the first sorted list. If the list is empty, the line will be empty.
- The second line contains space-separated integers representing the second sorted list. If the list is empty, the line will be empty.
outputFormat
Output a single line to standard output containing the merged sorted list. The integers must be space-separated.
## sample1 3 5 7
2 4 6 8
1 2 3 4 5 6 7 8