#C5122. Merging Two Sorted Arrays

    ID: 48737 Type: Default 1000ms 256MiB

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:

  1. An integer \(n\): the number of elements in the first sorted array.
  2. A line with \(n\) space-separated integers representing the first sorted array. If \(n = 0\), the line will be empty.
  3. An integer \(m\): the number of elements in the second sorted array.
  4. 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.

## sample
1
3
1 2 3
3
2 4 6
1 2 2 3 4 6