Question: Two stations A and B are connected to a network. Both stations have N number of addresses each. Each address is a posititve integer. The

Two stations A and B are connected to a network. Both stations have N number of addresses each. Each address is a posititve integer. The network pings the first address X of station A followed by next largest address Y from station B, where the X11. The first combination is (11,18).
Next, again 11 and 18 are picked. Now, as 21>18, thus, 21 is picked from A. As the path cannot end with an address from A,32 is also picked from B as 32>21. The next combination is {11,18,21,32} Next, 11 is picked from A. The next greater element in B is 32. Thus, 32 is also picked from B as 32>11. As there are no other addresses left to takecombination {11,32}, Similarly, for all the addresses, the combinations are to be found.
Let there be Z combinations formed. Find the sum of all the addresses in each combination, thus, Z sums are calculated.
Write a program to find out the maximum Max and minimum Min sums. Max is the maximum sum of all the elements of combinations and Min is the minimum sum of elements of combinations
Read the input from STDIN (standard input) and write the output to STDOUT (standard output). Do not print any arbitrary strings while reading the input or printing the output as those contribute to STDOUT
CONstraints:
1<= N<=13
INPUT Format:
FIRST line of input contains N, the total number of address values of Station A and Station B.
SECond line of input contains N integers, which are the address values of Station A, separated by a single white space.
THIRD line of input contains N integers, which are the address values of Station B, separated by a single white space.
OUTPUT
tge iutput contains Max and Min seperated by single space
Sample input
3
101525
52030
Sample Output
9030

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!