#C1583. Merge Two Sorted Arrays
Merge Two Sorted Arrays
Merge Two Sorted Arrays
You are given two arrays of integers which are sorted in non-decreasing order. Your task is to merge these two arrays into a single sorted array. The merging process should combine the elements of both arrays while maintaining the overall sort order.
Specifically, if you have two arrays A and B, you need to produce an output array C such that:
\( C = A \cup B \)
and \( C \) is sorted in non-decreasing order.
For example, if \( A = [1, 3, 5] \) and \( B = [2, 4, 6, 8] \), then the merged sorted array is \( [1,2,3,4,5,6,8] \).
inputFormat
The input is read from stdin and consists of four lines:
- An integer n representing the number of elements in the first array.
- n space-separated integers representing the elements of the first array.
- An integer m representing the number of elements in the second array.
- m space-separated integers representing the elements of the second array.
Note that either array can be empty (in which case its corresponding integer will be 0 and the next line may be empty).
outputFormat
The output should be a single line written to stdout containing the merged sorted array. The elements must be printed in non-decreasing order and separated by a single space. If the merged array is empty, output an empty line.
## sample3
1 3 5
4
2 4 6 8
1 2 3 4 5 6 8