#C12485. Merge Sorted Arrays
Merge Sorted Arrays
Merge Sorted Arrays
You are given two sorted arrays. Your task is to merge these two arrays into one single sorted array. In other words, if the two arrays are \(arr1\) and \(arr2\) with lengths \(n_1\) and \(n_2\) respectively, you need to produce an array that is the sorted union of these arrays.
Input Format:
- The first line contains an integer \(n_1\) that represents the number of elements in the first array.
- The second line contains \(n_1\) space-separated integers (if \(n_1 > 0\)).
- The third line contains an integer \(n_2\) that represents the number of elements in the second array.
- The fourth line contains \(n_2\) space-separated integers (if \(n_2 > 0\)).
Output Format:
- A single line containing the merged sorted array. The numbers should be printed separated by a single space.
Ensure that your code reads from the standard input and writes to the standard output.
inputFormat
The input is read from the standard input (stdin) and consists of four lines:
- The first line contains an integer \(n_1\) (the size of the first array).
- The second line contains \(n_1\) space-separated integers in sorted order. If \(n_1 = 0\), this line will be empty.
- The third line contains an integer \(n_2\) (the size of the second array).
- The fourth line contains \(n_2\) space-separated integers in sorted order. If \(n_2 = 0\), this line will be empty.
outputFormat
Output a single line containing the merged sorted array with each number separated by a space.
## sample4
1 3 5 7
4
2 4 6 8
1 2 3 4 5 6 7 8