#K50457. Maximum Pattern Length
Maximum Pattern Length
Maximum Pattern Length
Aisha loves playing with ribbons. She has two sets of ribbons: one set of red ribbons and one set of blue ribbons. Each ribbon has a fixed length. Aisha wants to create the longest possible pattern by arranging the ribbons. The catch is that she cannot cut a ribbon, so she must use each ribbon in its entirety. Although she likes alternating colors, she is free to choose the order in which she places the red and blue ribbons. It turns out that the maximum achievable length is simply the sum of the lengths of all red ribbons and all blue ribbons.
Given the two arrays of ribbon lengths, your task is to compute this maximum pattern length.
Note: The input begins with an integer T denoting the number of test cases. For each test case, the first integer n denotes the number of red ribbons followed by a line containing n space-separated integers. This is followed by an integer m denoting the number of blue ribbons and then a line containing m space-separated integers. The output for each test case is the maximum pattern length on a new line.
In mathematical terms, if ( R = [r_1, r_2, \dots, r_n] ) and ( B = [b_1, b_2, \dots, b_m] ), then the answer for each test case is given by:
[
\text{Answer} = \sum_{i=1}^{n} r_i + \sum_{j=1}^{m} b_j
]
inputFormat
The input is given from standard input and has the following format:
(T) (number of test cases)
Then, for each test case:
1. An integer (n) representing the number of red ribbons.
2. A line with (n) space-separated integers denoting the lengths of the red ribbons. (If (n = 0), this line will be empty.)
3. An integer (m) representing the number of blue ribbons.
4. A line with (m) space-separated integers denoting the lengths of the blue ribbons. (If (m = 0), this line will be empty.)
outputFormat
For each test case, output a single line containing one integer: the sum of the lengths of all red and blue ribbons, which represents the maximum pattern length.## sample
1
3
4 2 7
4
6 5 3 8
35
</p>