#C10122. Merge Sorted Arrays

    ID: 39293 Type: Default 1000ms 256MiB

Merge Sorted Arrays

Merge Sorted Arrays

You are given two arrays, each sorted in non-decreasing order. Your task is to merge these two arrays into one sorted array.

The algorithm should maintain the sorted order, meaning that if we denote the first array as \( A \) and the second array as \( B \), then the merged array \( M \) must satisfy \( M = \text{merge}(A, B) \) and be sorted in non-decreasing order.

For example, if \(A = [1,3,5]\) and \(B = [2,4,6]\), then the merged array is \([1,2,3,4,5,6]\).

inputFormat

The input consists of two lines read from standard input (stdin):

  • The first line contains the elements of the first sorted array separated by spaces. If the array is empty, the line will be empty.
  • The second line contains the elements of the second sorted array separated by spaces. If the array is empty, the line will be empty.

Each element is an integer which can be negative, zero, or positive.

outputFormat

The output (printed to standard output, stdout) is a single line containing the merged sorted array. The integers should be separated by a single space.

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