407281: GYM102741 I Stunt Jump Escape

Memory Limit:256 MB Time Limit:5 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

I. Stunt Jump Escapetime limit per test5 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Michael and Trevor have just pulled off the biggest heist Los Santos has ever seen! However, they must now escape the cops. In order to evade quickly, they decide to split up and drive dirt bikes across the map. The map is a hilly terrain laid out as a grid. Michael is traveling from the top row of the map to the bottom row, while Trevor is driving from the leftmost column to the rightmost column.

Every minute Michael must move downwards and Trevor must move rightwards. Specifically, Michael can move from position $$$(i, j)$$$ at time $$$t$$$ to either $$$(i+1, j-1)$$$, $$$(i+1, j)$$$ or $$$(i+1, j+1)$$$ at time $$$t+1$$$. Trevor can move from position $$$(i, j)$$$ at time $$$t$$$ to $$$(i-1, j+1)$$$, $$$(i, j+1)$$$ or $$$(i+1, j+1)$$$ at time $$$t+1$$$

To further confuse the cops and help them escape, they decide to meet somewhere along the way and swap vehicles quickly. This means that they must be in the same position at the same time at least once.

Both love pulling off stunts, and for each hill that they drive over, they will get points equal to the height of that hill. Help them maximize their total style points from this journey!

Input

The first line contains 2 space-separated integers $$$n$$$ (the number of rows) and $$$m$$$ (the number of columns). The following $$$n$$$ lines contain $$$m$$$ integers each, denoting the heights of each hill in the grid.

$$$ 1 \le n \le 10^3$$$

$$$ 1 \le m \le 10^3$$$

$$$ 1 \le height(i,j) \le 10^5$$$

Output

A single integer, the maximum style points that can be obtained by the pair.

ExamplesInput
2 2
1 1
2 2
Output
7
Input
3 3
1 2 3
4 5 6
7 8 9
Output
42
Note

If the starting position is the same, this counts as a 'meeting' and they need not meet again. Also, if they drive over the same hill they both get style points from that hill.

加入题单

上一题 下一题 算法标签: