Codeforces Round 990 (Div. 1) |
---|
Finished |
There is a matrix consisting of $$$2$$$ rows and $$$n$$$ columns. The rows are numbered from $$$1$$$ to $$$2$$$ from top to bottom; the columns are numbered from $$$1$$$ to $$$n$$$ from left to right. Let's denote the cell on the intersection of the $$$i$$$-th row and the $$$j$$$-th column as $$$(i,j)$$$. Each cell contains an integer; initially, the integer in the cell $$$(i,j)$$$ is $$$a_{i,j}$$$.
You can perform the following operation any number of times (possibly zero):
After performing the operations, you have to choose a path from the cell $$$(1,1)$$$ to the cell $$$(2,n)$$$. For every cell $$$(i,j)$$$ in the path except for the last, the next cell should be either $$$(i+1,j)$$$ or $$$(i,j+1)$$$. Obviously, the path cannot go outside the matrix.
The cost of the path is the sum of all integers in all $$$(n+1)$$$ cells belonging to the path. You have to perform the operations and choose a path so that its cost is maximum possible.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 5000$$$). The description of the test cases follows.
Each test case consists of three lines:
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, print one integer — the maximum cost of a path you can obtain.
31-10531 2 310 -5 -342 8 5 31 10 3 4
-5 16 29
Here are the explanations of the first three test cases of the example. The left matrix is the matrix given in the input, the right one is the state of the matrix after several column swaps (possibly zero). The optimal path is highlighted in green.
Name |
---|