#K78302. Merge Sorted Arrays
Merge Sorted Arrays
Merge Sorted Arrays
You are given two sorted arrays. Your task is to merge them into a single sorted array. The merged array should retain the sorted order. This is a classic problem that tests your ability to merge two sequences efficiently. Use the standard input (stdin) to read the arrays and output the merged result to standard output (stdout).
More formally, if the two sorted arrays are \(A = [a_1, a_2, \dots, a_n]\) and \(B = [b_1, b_2, \dots, b_m]\), you need to produce a merged array \(C\) such that \(C = A \cup B\) and \(C\) is sorted in non-decreasing order.
inputFormat
The input is given via standard input (stdin) and consists of four parts:
- An integer \(n\) representing the number of elements in the first sorted array.
- If \(n > 0\), a line with \(n\) space-separated integers representing the first array.
- An integer \(m\) representing the number of elements in the second sorted array.
- If \(m > 0\), a line with \(m\) space-separated integers representing the second array.
You may assume that the arrays are already sorted in non-decreasing order.
outputFormat
Output a single line containing the merged sorted array. The numbers should be separated by a single space. If the resulting array is empty, output an empty line.
## sample3
1 3 5
3
2 4 6
1 2 3 4 5 6