#C5393. Merge Two Sorted Arrays
Merge Two Sorted Arrays
Merge Two Sorted Arrays
You are given two sorted arrays consisting of integers. Your task is to merge these two arrays into one sorted array.
The problem requires you to implement a merge operation similar to the one used in the merge sort algorithm. The final merged array must contain all the elements from both arrays in non-decreasing order.
Note: The input is provided through standard input (stdin) and the output should be printed to standard output (stdout).
In mathematical terms, if the two arrays are \( A = [a_1, a_2, \dots, a_n] \) and \( B = [b_1, b_2, \dots, b_m] \) with \( a_1 \le a_2 \le \cdots \le a_n \) and \( b_1 \le b_2 \le \cdots \le b_m \), then the merged array is \( C = [c_1, c_2, \dots, c_{n+m}] \), where the sequence \( c_i \) is the sorted combination of \( A \) and \( B \).
inputFormat
The input is read from standard input 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 representing the elements of the first array.
- The third line contains an integer ( m ), the number of elements in the second sorted array.
- The fourth line contains ( m ) space-separated integers representing the elements of the second array.
It is guaranteed that each individual array is sorted in non-decreasing order.
outputFormat
Output to standard output a single line containing the merged sorted array. The elements should be space-separated.## sample
3
3 5 7
3
1 4 6
1 3 4 5 6 7