#K34907. Merge Two Sorted Arrays

    ID: 25413 Type: Default 1000ms 256MiB

Merge Two Sorted Arrays

Merge Two Sorted Arrays

You are given two sorted arrays. Your task is to merge them into a single sorted array without using any built-in sorting functions. You should implement the two-pointer technique to achieve this in \(O(n+m)\) time, where \(n\) and \(m\) are the lengths of the two arrays respectively.

The input is provided via standard input and consists of the length and elements of each array. The output should be the merged sorted array with elements separated by a single space.

Note: The arrays may contain negative values and duplicates.

inputFormat

The input is read from stdin and has the following format:

 n            // number of elements in the first array
 a1 a2 ... an // n space-separated sorted integers
 m            // number of elements in the second array
 b1 b2 ... bm // m space-separated sorted integers

outputFormat

Output the merged sorted array to stdout as a single line of space-separated integers.

## sample
4
1 3 5 7
4
2 4 6 8
1 2 3 4 5 6 7 8