
1. Move Right - From cell (i,j) to cell (i,j+1).
2. Move Down - From cell (i,j) to cell (i+1,j).
If the given matrix is ‘M’ = [ [1,3, 9] , [3,5,1 ].The path taken by
Ninja is 1,3,9,1 and the path taken by his friend is 1,3,5,1. So the total coins picked by his friend is 3+5 =8.
So, the score is 8.
The first line of the input contains an integer, 'T,’ denoting the number of test cases.
The first line of each test case contains a single integer, 'N’ denoting the number of columns in the matrix.
The next two lines contain N elements representing row 1 and row 2 of the matrix.
For each test case, print an integer corresponding to the score of the game if both players play optimally.
Print the output of each test case in a separate line.
You do not need to print anything. It has already been taken care of. Just implement the given function.
1 <= T <= 10
1 <= N<= 10^5.
1 <= M[i][j] <=5 * 10^3.
Time limit: 1 sec
If we observe a pattern in the path opted by Ninja,the path will be to this type given in the image below.It consist of a prefix of first row and the suffix of second row.
So,the second player(Ninja’s Friend) have either collect the coins from the suffix of first row or the prefix of the second row.But Ninja is playing first,so will try to pick the coins in such a way that his friends gets the minimum amount of coins.
There can be ‘N’ total different paths that can Ninja opt.So,we will iterate all these paths and find the minimum score his friend can achieve.