时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld
题目描述
You are given a matrix

of

rows and

columns, containing only integers.
For each row

, choose a non-empty interval

, such that the adjacent row's interval intersects, and maximize the sum of all integers over all intervals.
Formally, choose

such that

,
%20%5Cle%20%5Cmin(r_%7Bi%7D%2Cr_%7Bi%2B1%7D))
for all
)
, and maximize

输入描述:
The first line contains one integer
(
), representing the number of test cases.
For each test case, the first line contains two integers
(
), representing the size of the matrix.
The following
lines, each contain
integers
(
), representing each element of the matrix.
It is guaranteed that
.
输出描述:
For each test case, output one line containing a single integer, representing the answer.
示例1
输入
复制
5
4 4
-1 1 1 -1
1 1 -1 -1
-1 1 1 -1
-1 -1 1 1
3 4
2 -3 4 -1
1 2 -4 -7
1 1 -7 2
4 3
1 -1 1
-2 4 5
2 -3 2
6 -5 7
1 1
1
2 2
-1 -1
-1 -2