题目描述
Problem Description
dwango corporation has a large garden. This garden is divided into $ H $ rows from north to south and $ W $ columns from west to east, with each square being $ 1 $ meter by $ 1 $ meter. The square located $ i $th from the north and $ j $th from the west is denoted as square $ (i,j) $. The garden is filled with many flowers, and for each square, there is an integer representing the aesthetic value of the flowers in that square. Let $ B_{i,j} $ denote the aesthetic value of the flowers in square $ (i,j) $.
They plan to choose two rectangles, each consisting of at least one square, to enclose with fences, making the areas not enclosed by fences into paths. Note that no square can be contained in both rectangles, but overlapping fences are allowed.
The beauty of the entire garden is the sum of the aesthetic values of the squares enclosed by either of the two rectangles.
To create the ideal garden, they first need to determine the maximum beauty. Create a program to find the maximum beauty of the entire garden.
Input & Output Format
The input is given from the standard input in the following format:
$ H $ $ W $ $ B_{1,1} $ $ B_{1,2} $ … $ B_{1,W} $ : $ B_{H,1} $ $ B_{H,2} $ … $ B_{H,W} $
- The first line contains the lengths of the garden in the north-south and west-east directions, $H,\ W\ (2\ ≦\ H\ ≦\ 300,\ 2\ ≦\ W\ ≦\ 300)$, separated by spaces.
- The $1+i\ (1\ ≦\ i\ ≦\ H)$th line contains $ W $ integers representing the aesthetic values of the squares from north to $ i $th row, $B_{i,1},\ ...,B_{i,W}$, separated by spaces.
- $-10^9≦B_{i,j}≦10^9\ (1\ ≦\ i\ ≦\ H,\ 1\ ≦\ j\ ≦\ W)$ holds.
Input Format
None
Output Format
Output the maximum beauty of the entire garden when two rectangles are chosen, on one line. Ensure a newline at the end of the output.
Sample Input and Output
Sample Input #1
3 3
1 1 1
1 1 1
1 1 1
Sample Output #1
9
Sample Input #2
3 3
-1 -1 -1
-1 -1 -1
-1 -1 -1
Sample Output #2
-2
Sample Input #3
2 3
5 -1 8
-1 4 -1
Sample Output #3
16
Sample Input #4
4 4
5 2 -3 2
3 8 -3 -10
4 5 3 2
-5 -3 3 5
Sample Output #4
40
Notes/Hints
Scoring
This problem has partial scoring.
- If you solve the dataset where $H\ ≦\ 50,\ W\ ≦\ 50$, you will be awarded $ 50 $ points.
- If you solve all test cases, you will be awarded an additional $ 50 $ points.
Sample Explanation 1
Enclosing the entire garden with two rectangles results in the maximum beauty of $ 9 $.
Sample Explanation 2
Unfortunately, the beauty can be negative. Note that each rectangle must contain at least one square.
Sample Explanation 3
For example, the following enclosure method is possible.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分