#PS0000216. Tổng dấu X lớn nhất (X-Sum)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tổng dấu X lớn nhất (X-Sum)
X-Sum
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A rectangular chessboard has rows and columns, each cell containing a nonnegative integer. Place one bishop on any cell. It attacks every cell on the two diagonals through that cell, continuing to the board boundary in all four directions. The occupied cell counts once. Find the maximum possible sum of attacked cells.
Input
The first line contains two integers . Each of the next lines contains exactly integers. Each input file describes one board.
Output
Print the maximum attainable sum.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
4 4
1 2 2 1
2 4 2 4
2 2 3 1
2 4 2 4
Output
20
Explanation
At row 3, column 3, the two diagonal sums are 12 and 11, and the center is 3. The total is 20.
Example 2
Input
2 1
1
0
Output
1
Explanation
Each placement attacks only its own cell because there is one column.
Example 3
Input
3 3
1 1 1
1 1 1
1 1 1
Output
5
Explanation
The center attacks the four corners and itself.
Example 4
Input
3 3
0 1 1
1 0 1
1 1 0
Output
3
Explanation
Row 2, column 1 gives sum 3, and no placement gives more.