QOJ.ac

QOJ

Limite de temps : 2 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓

#6781. Calligrapher

Statistiques

Student E is very fond of calligraphy. Hearing that NOI 2013 has begun, he wants to write the letters "NOI" as a gift for everyone.

Student E has a magical piece of paper, which can be represented as a two-dimensional grid of $n$ rows and $m$ columns. For convenience, we define the coordinates of the bottom-left cell as $(1, 1)$ and the top-right cell as $(n, m)$. Each cell in the grid has an integer "luck value." Writing on the grid increases the total luck, which is exactly the sum of the luck values of all cells covered by the pen. Now, you need to write the three letters 'N', 'O', and 'I' on the grid.

The definitions of the three calligraphic letters are as follows:

  1. 'N' consists of several ($\ge 3$) rectangles with sides parallel to the coordinate axes. Let it consist of $K$ rectangles (labeled $1 \sim K$). Let the bottom-left coordinate of the $i$-th rectangle be $(L_i, B_i)$ and the top-right coordinate be $(R_i, T_i)$. The following must be satisfied: a) $L_i \le R_i$, $B_i \le T_i$; b) For any $1 < i \le K$, $L_i = R_{i-1} + 1$; c) For any $3 \le i < K$, $B_{i-1} - 1 \le T_i \le T_{i-1}$, $B_i \le B_{i-1}$; d) $B_2 > B_1$, $T_2 = T_1$, $R_{K-1} = R_K$, $T_{K-1} < T_K$;

  2. 'O' is obtained by taking a large rectangle $A$ and removing a smaller rectangle $B$. Both rectangles have sides parallel to the coordinate axes. Let the bottom-left coordinate of the large rectangle $A$ be $(u, v)$, its length be $W$, and its width be $H$. Then the small rectangle $B$ has its bottom-left coordinate at $(u+1, v+1)$, length $W-2$, and width $H-2$. The following must be satisfied: a) $W \ge 3, H \ge 3$; b) $u > R_K + 1$;

  3. 'I' consists of 3 solid rectangles with sides parallel to the coordinate axes, arranged from bottom to top, labeled 1, 2, and 3. Let the bottom-left coordinate of the $i$-th rectangle be $(P_i, Q_i)$ and the top-right coordinate be $(G_i, H_i)$. The following must be satisfied: a) $P_i \le G_i, Q_i \le H_i$; b) $P_1 = P_3 > G_K + W + 1$, $H_1 = H_3$; c) $Q_1 = H_1 = Q_2 - 1$, $H_2 + 1 = Q_3 = H_3$; d) $P_1 < P_2 \le G_2 < G_1$.

The figure below shows an example of 'N', 'O', and 'I'.

Additionally, all drawn shapes must not exceed the boundaries of the paper. Now, Student E wants to know the maximum total luck he can achieve.

Input

The first line contains two positive integers $n$ and $m$, representing the number of rows and columns of the grid, respectively. The next $n$ lines each contain $m$ integers. The $j$-th number in the $(i+1)$-th line represents the luck value of the cell $(j, n-i+1)$.

Output

Output a single integer $T$, representing the maximum luck Student E can obtain.

Examples

Input 1

3 13
1 1 -1 -1 1 -1 1 1 1 -1 1 1 1
1 -1 1 -1 1 -1 1 -1 1 -1 -1 1 -1
1 -1 -1 1 1 -1 1 1 1 -1 1 1 1

Output 1

24

Note

The cells highlighted in the grid below represent the optimal placement for the letters 'N', 'O', and 'I'.

1  1 -1 -1  1 -1  1  1  1 -1  1  1  1
1 -1  1 -1  1 -1  1 -1  1 -1 -1  1 -1
1 -1 -1  1  1 -1  1  1  1 -1  1  1  1

Input 2

3 13
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Output 2

-20

Note

The following is one possible optimal solution; others may exist.

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1

Input 3

(input data)

Output 3

(output data)

Constraints

For all test data, it is guaranteed that $n \ge 3, m \ge 12$.

Test Case ID $n$ $m$ Luck Value Range
1 $= 3$ $= 12$ $[-50, 50]$
2 $= 3$ $= 12$ $[-50, 50]$
3 $= 3$ $= 12$ $[-50, 50]$
4 $= 3$ $= 12$ $[-50, 50]$
5 $\le 10$ $\le 20$ $[-50, 50]$
6 $\le 10$ $\le 20$ $[-50, 50]$
7 $\le 10$ $\le 20$ $[-50, 50]$
8 $\le 10$ $\le 20$ $[-50, 50]$
9 $\le 150$ $\le 500$ $= 1$
10 $\le 150$ $\le 500$ $= 1$
11 $\le 80$ $\le 80$ $[-200, 200]$
12 $\le 80$ $\le 80$ $[-200, 200]$
13 $\le 80$ $\le 80$ $[-200, 200]$
14 $\le 80$ $\le 80$ $[-200, 200]$
15 $\le 150$ $\le 500$ $[-200, 200]$
16 $\le 150$ $\le 500$ $[-200, 200]$
17 $\le 150$ $\le 500$ $[-200, 200]$
18 $\le 150$ $\le 500$ $[-200, 200]$
19 $\le 150$ $\le 500$ $[-200, 200]$
20 $\le 150$ $\le 500$ $[-200, 200]$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.