#K63957. Merge Two Sorted Arrays
Merge Two Sorted Arrays
Merge Two Sorted Arrays
You are given two sorted arrays. Your task is to merge these arrays into a single sorted array.
More formally, let \(A = [a_1, a_2, \ldots, a_n]\) and \(B = [b_1, b_2, \ldots, b_m]\) be two sorted arrays. You need to produce an array \(C\) such that \(C\) is the merger of \(A\) and \(B\) in non-decreasing order.
Input Format: The input is read from stdin
and structured as described below.
Output Format: Output the merged sorted array to stdout
in one line with elements separated by a single space.
inputFormat
The first line contains two integers \(n\) and \(m\) separated by a space, where \(n\) is the number of elements in the first sorted array and \(m\) is the number of elements in the second sorted array.
The second line contains \(n\) space-separated integers representing the first sorted array.
The third line contains \(m\) space-separated integers representing the second sorted array.
outputFormat
A single line containing \(n+m\) space-separated integers which represent the merged sorted array.
## sample3 3
1 3 5
2 4 6
1 2 3 4 5 6
</p>