
Let the stacks be-
A = [2 , 2, 1, 1]
B = [1, 4]
C = [4]
We can remove the topmost element from stack A and the topmost element from stack B.
The final stacks after removal of the elements are-
A = [2, 1, 1]
B = [4]
C = [4]
Sum of elements of stack A = 4.
Sum of elements of stack B = 4.
Sum of elements of stack C = 4.
The maximum possible equal sum is equal to 4.
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test case follows.
Then the first line of each test case contains three space separated positive integers ‘len1’, ‘len2’ and ‘len3’ denoting the length of the stacks.
The second line of each test case contains lenA space separated positive integers the elements of stack A.
The third line of each test case contains lenB space separated positive integers the elements of stack B.
The third line of each test case contains lenC space separated positive integers the elements of stack C.
For each test case, Print the maximum possible equal sum after the removal of some top elements from each of the stack.
Output for each test case will be printed in a new line.
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 100
1 <= lenA, lenB, lenC <= 5000
1 <= A[i], B[i], C[i] <= 10^5
Time Limit: 1sec
The key observation here is to compare the sum of each stack and if they are not the same, we remove the top element from the stack having the maximum sum.
The algorithm will be-