You are given an N x M matrix ‘MAT’ and an integer ‘K’. All rows in the matrix have values in sorted order. You can choose 1 integer from each row and make an array of length ‘N’. Your task is to find the smallest k-th smallest array sum out of all the possibilities.
Input Format:
The first line of the input contains ‘T’ denoting the number of test cases.
In the first line of each test case take three space-separated integers, ‘N’, ‘M’, and ‘K’.
Next N lines contains M space-separated integers MAT[i][j], denoting value stored in position (i, j) in matrix.
Output Format:
For each test case, print a single line containing a single integer denoting the k-th smallest array sum.
The output for every test case will be printed in a separate line.
Note:
You don’t need to print anything; It has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 5
1 <= N, M <= 100
1 <= K <= min(100,N ^ 2)
0 <= MAT[ i ][ j ] <= 2000
MAT[ i ][ j ] <= MAT[ i ][ j + 1 ]
Time Limit: 1 sec.