#K33987. Merge Two Sorted Arrays

    ID: 25209 Type: Default 1000ms 256MiB

Merge Two Sorted Arrays

Merge Two Sorted Arrays

You are given two arrays, each sorted in non-decreasing order. The task is to merge these two arrays into a single sorted array, also in non-decreasing order. This problem requires you to read the arrays from standard input (stdin), perform the merge, and output the merged array to standard output (stdout).

Note that the arrays might contain duplicate elements.

inputFormat

The input is given from stdin. The format is as follows:

  • The first line contains an integer n, the number of elements in the first array.
  • The second line contains n space-separated integers representing the first sorted array.
  • The third line contains an integer m, the number of elements in the second array.
  • The fourth line contains m space-separated integers for the second sorted array.

For example: 3 1 3 5 3 2 4 6

outputFormat

Output a single line to stdout containing the merged sorted array. The numbers should be space-separated. For the example above, the correct output would be: 1 2 3 4 5 6## sample

3
1 3 5
3
2 4 6
1 2 3 4 5 6