#C13053. Merge Sorted Arrays

    ID: 42549 Type: Default 1000ms 256MiB

Merge Sorted Arrays

Merge Sorted Arrays

You are given two sorted arrays. Your task is to merge these arrays into a single sorted array while preserving the order and duplicates.

The merging process is based on the two pointers technique. Let \( n \) be the number of elements in the first array and \( m \) in the second array. The time complexity of the solution should be \( O(n+m) \).

inputFormat

The input is read from standard input (stdin) and contains four lines:

  • The first line is an integer \( n \) representing the number of elements in the first sorted array.
  • The second line contains \( n \) space-separated integers representing the first sorted array. If \( n = 0 \), this line will be empty.
  • The third line is an integer \( m \) representing the number of elements in the second sorted array.
  • The fourth line contains \( m \) space-separated integers representing the second sorted array. If \( m = 0 \), this line will be empty.

outputFormat

Output to standard output (stdout) the merged sorted array as space-separated integers on a single line. If the merged array is empty, output an empty line.

## sample
3
1 2 3
0

1 2 3

</p>