#C14713. Merge Sorted Arrays

    ID: 44393 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.

The expected time complexity is \(O(n+m)\), where \(n\) and \(m\) are the sizes of the two arrays. Use an efficient two-pointer technique to accomplish this.

inputFormat

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

  • The first line contains 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 contains 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 the merged sorted array to standard output (stdout) as space-separated integers in a single line.

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