#C13939. Merge Two Sorted Arrays
Merge Two Sorted Arrays
Merge Two Sorted Arrays
You are given two sorted arrays. Your task is to merge these two arrays into a single sorted array. The merging process should preserve the order and include all elements from both arrays.
More formally, given two arrays \(A\) and \(B\) where:
- \(A = [a_1, a_2, \dots, a_n]\) is sorted in non-decreasing order.
- \(B = [b_1, b_2, \dots, b_m]\) is sorted in non-decreasing order.
You need to produce an array \(C\) of length \(n+m\) which is the result of merging \(A\) and \(B\) such that \(C\) is also sorted in non-decreasing order.
inputFormat
The first line contains two integers \(n\) and \(m\), representing the lengths of the first and second arrays respectively.
The second line contains \(n\) integers separated by spaces, representing the first sorted array. If \(n = 0\), this line will be empty.
The third line contains \(m\) integers separated by spaces, representing the second sorted array. If \(m = 0\), this line will be empty.
outputFormat
Output the merged sorted array. The elements should be printed in a single line separated by a single space.
## sample3 3
1 3 5
2 4 6
1 2 3 4 5 6