#C14114. Merge Sorted Arrays

    ID: 43728 Type: Default 1000ms 256MiB

Merge Sorted Arrays

Merge Sorted Arrays

Given two sorted arrays, your task is to merge them into one single sorted array. You are required to implement an efficient two-pointer algorithm which operates in (\mathcal{O}(n+m)) time, where (n) and (m) are the sizes of the two arrays.

It is guaranteed that each of the two input arrays is already sorted in non-decreasing order.

inputFormat

The input consists of two lines. The first line contains the first sorted array as space-separated integers. The second line contains the second sorted array as space-separated integers. If an array is empty, the corresponding line will be empty.

outputFormat

Print the merged sorted array as a single line with elements separated by a single space. If the merged array is empty, output an empty line.## sample

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