#C13648. Merge Sorted Arrays
Merge Sorted Arrays
Merge Sorted Arrays
You are given two sorted arrays of integers. Your task is to merge them into a single sorted array.
The two arrays are provided via standard input, each on a separate line. If an array is empty, the corresponding input line will be empty.
Formally, if you have two arrays \(A\) and \(B\) such that \[ A = [a_1, a_2, \dots, a_m]\quad\text{and}\quad B = [b_1, b_2, \dots, b_n], \] you need to produce the array \[ C = [c_1, c_2, \dots, c_{m+n}], \] which is the sorted merger of \(A\) and \(B\). This is a classical algorithm problem with a time complexity of \(O(m+n)\) if done optimally.
inputFormat
The input consists of two lines read from stdin:
- The first line contains space-separated integers representing the first sorted array. It can be an empty line indicating an empty array.
- The second line contains space-separated integers representing the second sorted array. It can also be empty.
outputFormat
Output a single line to stdout containing the merged sorted array, with each integer separated by a single space. If the merged array is empty, output an empty line.
## sample
1 2 3
1 2 3