Coin Rows solution codeforces
Alice and Bob are playing a game on a matrix, consisting ofrows and columns. The cell in the -th row in the -th column contains coins in it.
Initially, both Alice and Bob are standing in a cell. They are going to perform a sequence of moves to reach a cell .
The possible moves are:
- Move right — from some cell to ;
- Move down — from some cell to .
First, Alice makes all her moves until she reaches . 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 but Alice didn’t.and collects the coins in all cells that he visited,
The score of the game is the total number of coins Bob collects.
Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally?
The first line contains a single integer( ) — the number of testcases.
Then the descriptions oftestcases follow.
The first line of the testcase contains a single integer( ) — the number of columns of the matrix.
The-th of the next lines contain integers ( ) — the number of coins in the cell in the -th row in the -th column of the matrix.
The sum ofover all testcases doesn’t exceed .
For each testcase print a single integer — the score of the game if both players play optimally.
3 3 1 3 7 3 5 1 3 1 3 9 3 5 1 1 4 7
7 8 0
The paths for the testcases are shown on the following pictures. Alice’s path is depicted in red and Bob’s path is depicted in blue.