
Assume that you are given three stacks {2,5}, {5,1,6} and {7,2,3,4}. Initially sum of stack one is 7, stack 2 is 12, and stack 3 is 16. But if we remove 5 from stack 2 that is top of stack its sum becomes 7. Similarly, if we remove 7 and then 2 from stack 3 then its sum also becomes 7 so the maximum possible sum for this case is 7.
1. If no such sum is possible return zero.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next 6 * T lines represent the ‘T’ test cases as follows-
The first line of each test case contains a single integer n1 which denotes the size of the first
The second line of each test case contains space-separated integers that represent elements of the first stack and the starting element is the top of the stack.
Similarly, the next 4 lines represent the other two stacks in the same manner.
For each test case, print a single line containing a single integer denoting is the maximum possible equal sum for the three stacks.
The output of each test case will be printed in a separate line.
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= N <= 10000
1 <= DATA <= 10 ^ 6
Where ‘T’ is the total number of test cases, where N denotes the number of elements in any of the stacks and ‘DATA’ represents the data in the stacks.
Time limit: 1 sec.
The idea is to compare the sum of each stack and if they are not same, then we will remove the top element of the stack having the maximum sum.