MicrosoftOA #38
Maximum Sum of Two Non-Attacking Rooks
估计中等可在线判题
Place exactly two rooks on a rectangular board; they must be in different rows and different columns. Find the maximum sum of the scores of their cells. The original site's sample input is not rectangular, so this site uses independent examples consistent with the statement.
输入格式
This site's ranges: the first line contains N M (2..500), followed by N lines each with M integer scores (−10⁹..10⁹).
输出格式
Output a single integer, the answer.
样例 1
输入:
2 2
1 4
2 3
输出:
6
样例 2
输入:
2 2
-5 -1
-2 -3
输出:
-3
样例 3
输入:
2 2
9 1
8 2
输出:
11
样例说明
Example 1: take the top-right 4 and the bottom-left 2, for a sum of 6.
Example 2: two rooks must be placed, so take −1 and −2, for a maximum sum of −3.
Example 3: 9 and 8 are in the same column and cannot be paired, so take 9 and 2, for a sum of 11.