{"id":"9016dd16-9d2e-4600-997d-2185b345cabd","name":"Coin Rows","description":"Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the ith row in the jth column contains a[i][j] coins in it.\r\nInitially, both Alice and Bob are standing in a cell (1,1). They are going to perform a sequence of moves to reach a cell (2,m). The moves allowed are right and down one step.\r\n\r\nFirst, Alice makes all her moves until she reaches (2,m). she collects the coins in all cells she visit (including the starting cell).\r\nWhen Alice finishes, Bob starts his journey. He also performs the moves to reach (2,m) and collects the coins in all cells that he visited, but Alice didn't.\r\nThe score of the game is the total number of coins Bob collects.\r\nAlice wants to minimize score of the game. Bob wants to maximize score of the game. What will be the score of the game if both players play optimally?","inputFormat":"The first line contains a single integer t, number of test cases.\r\nThe first line of the testcase contains a single integer m, the number of column in the matrix.\r\nThe ith of the next 2 lines contain m integers. the number of coins in the cell in the ith row in the jth column of the matrix.","outputFormat":"For each testcase print a single integer the score of the game if both players play optimally.","constraints":"1 <= t <= 100\r\n1 <= m <= 10001\r\n1 <= a[i][j] <= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n3\r\n1 4 7\r\n3 5 2\r\n3\r\n1 3 9\r\n3 6 1\r\n1\r\n4\r\n7\r\n","sampleOutput":"7\r\n9\r\n0\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"69a201c4-0167-4796-8f47-94965d7eaabf","name":"Coin Rows","slug":"coin-rows","type":1}],"next":{"id":"ca311230-0a6f-4191-b99a-e259f0e2be15","name":"String Polynomial Hashing","type":1,"slug":"string-polynomial-hashing"},"prev":{"id":"69b9695f-ba89-4aca-ace1-4ca7dbbf5c38","name":"Say No To Palindrome","type":1,"slug":"say-no-to-palindrome"}}}

Coin Rows

Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the ith row in the jth column contains a[i][j] coins in it. Initially, both Alice and Bob are standing in a cell (1,1). They are going to perform a sequence of moves to reach a cell (2,m). The moves allowed are right and down one step. First, Alice makes all her moves until she reaches (2,m). she collects the coins in all cells she visit (including the starting cell). When Alice finishes, Bob starts his journey. He also performs the moves to reach (2,m) and collects the coins in all cells that he visited, but Alice didn't. The score of the game is the total number of coins Bob collects. Alice wants to minimize score of the game. Bob wants to maximize score of the game. What will be the score of the game if both players play optimally?

{"id":"9016dd16-9d2e-4600-997d-2185b345cabd","name":"Coin Rows","description":"Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the ith row in the jth column contains a[i][j] coins in it.\r\nInitially, both Alice and Bob are standing in a cell (1,1). They are going to perform a sequence of moves to reach a cell (2,m). The moves allowed are right and down one step.\r\n\r\nFirst, Alice makes all her moves until she reaches (2,m). she collects the coins in all cells she visit (including the starting cell).\r\nWhen Alice finishes, Bob starts his journey. He also performs the moves to reach (2,m) and collects the coins in all cells that he visited, but Alice didn't.\r\nThe score of the game is the total number of coins Bob collects.\r\nAlice wants to minimize score of the game. Bob wants to maximize score of the game. What will be the score of the game if both players play optimally?","inputFormat":"The first line contains a single integer t, number of test cases.\r\nThe first line of the testcase contains a single integer m, the number of column in the matrix.\r\nThe ith of the next 2 lines contain m integers. the number of coins in the cell in the ith row in the jth column of the matrix.","outputFormat":"For each testcase print a single integer the score of the game if both players play optimally.","constraints":"1 <= t <= 100\r\n1 <= m <= 10001\r\n1 <= a[i][j] <= 10000","sampleCode":{"cpp":{"code":""},"java":{"code":"\r\nimport java.util.*;\r\nimport java.lang.*;\r\nimport java.io.*;\r\n\r\nclass Main {\r\n\r\n public static void main(String[] args) throws Exception {\r\n\r\n }\r\n\r\n}\r\n"},"ruby":{"code":""},"python":{"code":""},"javascript":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"3\r\n3\r\n1 4 7\r\n3 5 2\r\n3\r\n1 3 9\r\n3 6 1\r\n1\r\n4\r\n7\r\n","sampleOutput":"7\r\n9\r\n0\r\n\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"a2073e25-96a1-4875-b400-f40bbe2edd95","name":"Text Processing For Experts","slug":"text-processing-for-experts-859","type":0},{"id":"69a201c4-0167-4796-8f47-94965d7eaabf","name":"Coin Rows","slug":"coin-rows","type":1}],"next":{"id":"ca311230-0a6f-4191-b99a-e259f0e2be15","name":"String Polynomial Hashing","type":1,"slug":"string-polynomial-hashing"},"prev":{"id":"69b9695f-ba89-4aca-ace1-4ca7dbbf5c38","name":"Say No To Palindrome","type":1,"slug":"say-no-to-palindrome"}}}
plane

Editor


Loading...

Coin Rows

medium

Alice and Bob are playing a game on a matrix, consisting of 2 rows and m columns. The cell in the ith row in the jth column contains a[i][j] coins in it. Initially, both Alice and Bob are standing in a cell (1,1). They are going to perform a sequence of moves to reach a cell (2,m). The moves allowed are right and down one step. First, Alice makes all her moves until she reaches (2,m). she collects the coins in all cells she visit (including the starting cell). When Alice finishes, Bob starts his journey. He also performs the moves to reach (2,m) and collects the coins in all cells that he visited, but Alice didn't. The score of the game is the total number of coins Bob collects. Alice wants to minimize score of the game. Bob wants to maximize score of the game. What will be the score of the game if both players play optimally?

Constraints

1 <= t <= 100 1 <= m <= 10001 1 <= a[i][j] <= 10000

Format

Input

The first line contains a single integer t, number of test cases. The first line of the testcase contains a single integer m, the number of column in the matrix. The ith of the next 2 lines contain m integers. the number of coins in the cell in the ith row in the jth column of the matrix.

Output

For each testcase print a single integer the score of the game if both players play optimally.

Example

Sample Input

3 3 1 4 7 3 5 2 3 1 3 9 3 6 1 1 4 7

Sample Output

7 9 0

Discussions

Show Discussion

Related Resources

related resources

Turning Off Zen Mode