#33. 按优先级合并数组
按优先级合并数组
Array Merge
Background
Congcong has recently been learning about array operations and encountered an interesting small challenge. He needs to construct a new short array from two given arrays according to specific rules.
Problem Description
Given two integer arrays, and , return a new array of length . The new array should contain, as much as will fit, the elements from followed by the elements from . The arrays may be of any length, including , but it is guaranteed that there will be or more elements available between the two arrays.
Input Format
Input is given from standard input in the following format.
A single line containing two integer arrays, and . Elements within each array are space-separated and enclosed in square brackets
[]. The two arrays are separated by a single space.
Output Format
Output is printed to standard output in the following format.
A single line containing an integer array of length . Elements within the array are separated by a comma and a space
,, and enclosed in square brackets[].
Sample
[4 5] [1 2 3]
[4, 5]
[4] [1 2 3]
[4, 1]
[] [1 2]
[1, 2]
Sample Explanation
Sample 1: Array contains elements [4, 5], which is enough to fill the result array. Thus, the result is [4, 5].
Sample 2: Array contains element [4]. We take all elements from , then take the first element [1] from array to fill the remaining position. Thus, the result is [4, 1].
Sample 3: Array is empty. We take the first elements [1, 2] from array to fill the result array. Thus, the result is [1, 2].
Constraints
Time limit: second, Memory limit: KiB.