#C1583. Merge Two Sorted Arrays

    ID: 44804 Type: Default 1000ms 256MiB

Merge Two Sorted Arrays

Merge Two Sorted Arrays

You are given two arrays of integers which are sorted in non-decreasing order. Your task is to merge these two arrays into a single sorted array. The merging process should combine the elements of both arrays while maintaining the overall sort order.

Specifically, if you have two arrays A and B, you need to produce an output array C such that:

\( C = A \cup B \)

and \( C \) is sorted in non-decreasing order.

For example, if \( A = [1, 3, 5] \) and \( B = [2, 4, 6, 8] \), then the merged sorted array is \( [1,2,3,4,5,6,8] \).

inputFormat

The input is read from stdin and consists of four lines:

  1. An integer n representing the number of elements in the first array.
  2. n space-separated integers representing the elements of the first array.
  3. An integer m representing the number of elements in the second array.
  4. m space-separated integers representing the elements of the second array.

Note that either array can be empty (in which case its corresponding integer will be 0 and the next line may be empty).

outputFormat

The output should be a single line written to stdout containing the merged sorted array. The elements must be printed in non-decreasing order and separated by a single space. If the merged array is empty, output an empty line.

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