#C12364. Merge Sorted Lists
Merge Sorted Lists
Merge Sorted Lists
You are given two sorted lists. Your task is to merge them into one sorted list. The lists may contain duplicate integers. However, if any element in the input is not an integer, you should output Lists must only contain integers
.
Formally, let \(L_1\) and \(L_2\) be two lists of integers such that each is sorted in non-decreasing order. You need to compute the merged list \(L\) such that:
[ L = \text{merge}(L_1, L_2) \quad \text{and} \quad L \text{ is sorted in non-decreasing order.} ]
If any element of either list is not an integer, output the exact string "Lists must only contain integers".
Examples:
- Input:
1 3 5
and2 4 6
→ Output:[1, 2, 3, 4, 5, 6]
- Input:
1 2 3
anda b c
→ Output:Lists must only contain integers
- Input:
5 10
and-1 7 9
→ Output:[-1, 5, 7, 9, 10]
inputFormat
The input consists of two lines:
- The first line contains the elements of the first sorted list, separated by spaces. It may be empty, representing an empty list.
- The second line contains the elements of the second sorted list, separated by spaces. It may also be empty.
Each element should be a valid integer. If any element is not an integer, the program should output Lists must only contain integers
.
outputFormat
If both lists contain only integers, output the merged sorted list in Python list format (e.g., [1, 2, 3]). Otherwise, output the exact error string: Lists must only contain integers
.
[]