Given n arrays of size m each. Find maximum sum obtained by selecting a number from each array such that the element selected from the i-th array is more than the element selected from (i-1)-th array. If maximum sum cannot be obtained then return 0.
The first line contains an integer T denoting the number of test cases. For each test case, the first line contains two integers n & m denoting the size of 2-D Array. The next line n contains m elements each.
For each test case, the output is the maximum sum that can be obtained, if not return 0.
1 7 4 3
4 2 5 1
9 5 1 8
9 8 7
6 5 4
3 2 1
1. We can select 4 from the first array, 5 from second array and 9 from the third array.
2. As maximum sum cannot be obtained according to condition, hence 0.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.