Working out

题意翻译

夏天要到了,$\texttt{dxbt}$ 和 $\texttt{songke}$ 决定去健身。它们要去的健身房可以被看做一个 $n$ 行 $m$ 列的矩阵。定义 $a_{i,j}$ 为在健身房第 $i$ 行第 $j$ 列运动后消耗的卡路里。 $\texttt{dxbt}$ 从 $\left(1,1\right)$ 出发,要去 $\left(n,m\right)$。并且,他只能从 $\left(i,j\right)$ 走到 $\left(i+1,j\right)$ 或 $\left(i,j+1\right)$;$\texttt{songke}$ 从 $\left(n,1\right)$ 出发,要去 $\left(1,m\right)$。并且,他只能从 $\left(i,j\right)$ 走到 $\left(i-1,j\right)$ 或 $\left(i,j+1\right)$。 由于 $\texttt{dxbt}$ 和 $\texttt{songke}$ 要聚在一起发张自拍,他们必须在健身房的某行某列相遇。由于他们没有好好健身,所以在自拍地点的卡路里消耗不计入总卡路里消耗值。 如果 $\texttt{dxbt}$ 和 $\texttt{songke}$ 中任何一个人完成了健身,则健身结束。你的任务是求出 $\texttt{dxbt}$ 和 $\texttt{songke}$ 可以消耗的最大总卡路里值。 另外,由于他们的健身速度不一定相同,所以可以走过的路线长度也不一定相同。 ### 输入格式 第一行包含两个整数 $n,m(3\le n,m\le1000)$,代表健身房的行数、列数。 接下来 $n$ 行每行 $m$ 个整数,表示 $a_{i,j}$。 ### 输出格式 一行一个整数,表示他们可能消耗的总卡路里的最大值。 ### 说明 对于样例 $1$,$\texttt{dxbt}$ 可以选择: $$ \left(1,1\right)\rightarrow\left(1,2\right)\rightarrow\left(2,2\right)\rightarrow\left(3,2\right)\rightarrow\left(3,3\right) $$ $\texttt{songke}$ 可以选择: $$ \left(3,1\right)\rightarrow\left(2,1\right)\rightarrow\left(2,2\right)\rightarrow\left(2,3\right)\rightarrow\left(1,3\right) $$

题目描述

Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix $ a $ with $ n $ lines and $ m $ columns. Let number $ a[i][j] $ represents the calories burned by performing workout at the cell of gym in the $ i $ -th line and the $ j $ -th column. Iahub starts with workout located at line $ 1 $ and column $ 1 $ . He needs to finish with workout $ a[n][m] $ . After finishing workout $ a[i][j] $ , he can go to workout $ a[i+1][j] $ or $ a[i][j+1] $ . Similarly, Iahubina starts with workout $ a[n][1] $ and she needs to finish with workout $ a[1][m] $ . After finishing workout from cell $ a[i][j] $ , she goes to either $ a[i][j+1] $ or $ a[i-1][j] $ . There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout. If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

输入输出格式

输入格式


The first line of the input contains two integers $ n $ and $ m $ ( $ 3<=n,m<=1000 $ ). Each of the next $ n $ lines contains $ m $ integers: $ j $ -th number from $ i $ -th line denotes element $ a[i][j] $ ( $ 0<=a[i][j]<=10^{5} $ ).

输出格式


The output contains a single number — the maximum total gain possible.

输入输出样例

输入样例 #1

3 3
100 100 100
100 1 100
100 100 100

输出样例 #1

800

说明

Iahub will choose exercises $ a[1][1]→a[1][2]→a[2][2]→a[3][2]→a[3][3] $ . Iahubina will choose exercises $ a[3][1]→a[2][1]→a[2][2]→a[2][3]→a[1][3] $ .