#C4864. Merge Two Sorted Arrays
Merge Two Sorted Arrays
Merge Two Sorted Arrays
You are given two sorted arrays \(A\) and \(B\). Your task is to merge these two arrays into a single sorted array. The arrays are provided in the following format: first, an integer representing the number of elements in the array, followed by that many integers in sorted order. You need to produce a merged array that is also sorted.
Example:
Input: 4 1 3 5 7 4 2 4 6 8 Output: 1 2 3 4 5 6 7 8
The problem requires you to utilize the merging technique without employing any additional unnecessary data structures. However, using a new list/array for the merged result is acceptable.
inputFormat
The input is read from the standard input (stdin) and consists of four lines:
- The first line contains an integer \(n\), the number of elements in the first sorted array.
- The second line contains \(n\) space-separated integers in sorted order.
- The third line contains an integer \(m\), the number of elements in the second sorted array.
- The fourth line contains \(m\) space-separated integers in sorted order.
outputFormat
Output a single line containing the merged sorted array as space-separated integers. Print nothing if both arrays are empty.
## sample4
1 3 5 7
4
2 4 6 8
1 2 3 4 5 6 7 8
</p>