#C5122. Merging Two Sorted Arrays
Merging Two Sorted Arrays
Merging Two Sorted Arrays
This problem requires you to merge two sorted arrays into one single sorted array.
You will be given two sorted arrays and your task is to combine them and output the resulting sorted array.
The merge must be done using a two-pointer technique with an optimal time complexity of \(O(n+m)\), where \(n\) and \(m\) are the lengths of the respective arrays. Use LaTeX formatting for mathematical formulas.
inputFormat
The input will be read from stdin and will consist of multiple test cases. The first line contains a single integer \(T\) denoting the number of test cases. Each test case is represented by four lines:
- An integer \(n\): the number of elements in the first sorted array.
- A line with \(n\) space-separated integers representing the first sorted array. If \(n = 0\), the line will be empty.
- An integer \(m\): the number of elements in the second sorted array.
- A line with \(m\) space-separated integers representing the second sorted array. If \(m = 0\), the line will be empty.
Note: All arrays are sorted in non-decreasing order.
outputFormat
For each test case, output a single line to stdout containing the merged sorted array. The elements should be separated by a single space.
## sample1
3
1 2 3
3
2 4 6
1 2 2 3 4 6