#C14094. Merge Sorted Arrays

    ID: 43705 Type: Default 1000ms 256MiB

Merge Sorted Arrays

Merge Sorted Arrays

You are given two sorted arrays and your task is to merge them into one sorted array while maintaining the non-decreasing order.

Let the first array be ( arr1 = [a_1, a_2, \dots, a_n] ) and the second array be ( arr2 = [b_1, b_2, \dots, b_m] ). The result should be a merged array ( merged = [c_1, c_2, \dots, c_{n+m}] ) such that the following condition holds for all valid indices ( i ):
( c_i \leq c_{i+1} ).

inputFormat

The input is given via standard input (stdin) and consists of two parts:

1. The first line contains an integer ( n ) representing the number of elements in the first array, followed by a line with ( n ) integers in non-decreasing order.

2. The next line contains an integer ( m ) representing the number of elements in the second array, followed by a line with ( m ) integers in non-decreasing order.

You can assume that the arrays may include duplicates and negative numbers.

outputFormat

Output to standard output (stdout) a single line containing the merged sorted array. The elements must be separated by a single space.## sample

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