| TheForces Round #44 (DIV3.5-Forces) |
|---|
| Finished |
There is a classical problem: given an $$$n \times n$$$ grid, where the value of each cell $$$(i, j)$$$ is $$$a_{i,j}$$$. You need to find the path with the maximum sum from $$$(1, 1)$$$ to $$$(n, n)$$$ when you can only move right or down.
Support $$$q$$$ modifications: each modification gives an integer $$$k$$$, where $$$2 \le k \le 2n$$$. For all cells $$$(i, j)$$$ such that $$$i + j = k$$$ ($$$1 \le i$$$, $$$j \le n$$$), modify $$$a_{i,j}$$$ to $$$v$$$. You need to output the answer after each modification. Note the impact of a modification is permanent.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 200$$$, $$$1 \le q \le 10^5$$$).
The $$$i$$$-th of the following $$$n$$$ lines contains $$$n$$$ integers $$$a_{i,1}, a_{i,2}, \ldots, a_{i,n}$$$ ($$$1 \le a_{i,j} \le 10^9$$$).
The $$$i$$$-th of the following $$$q$$$ lines contains two integers $$$k$$$ and $$$v$$$ ($$$2 \le k \le 2n$$$, $$$1 \le v \le 10^9$$$).
It is guaranteed that the sum of $$$n^2$$$ over all test cases does not exceed $$$4 \cdot 10^4$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output a single integer in a new line — the maximum path sum from $$$(1, 1)$$$ to $$$(n, n)$$$ after the modification.
22 31 23 42 23 44 52 21 11 13 12 5
9 10 11 3 7
In the first test case, after the first modification, the grid becomes
| $$$2$$$ | $$$2$$$ |
| $$$3$$$ | $$$4$$$ |
The optimal path is $$$(1,1) \rightarrow (2,1) \rightarrow (2,2)$$$. The maximum path sum is $$$2+3+4=9$$$.
After the second modification, the grid becomes
| $$$2$$$ | $$$4$$$ |
| $$$4$$$ | $$$4$$$ |
After the third modification, the grid becomes
| $$$2$$$ | $$$4$$$ |
| $$$4$$$ | $$$5$$$ |
| Name |
|---|


