1982.Maximum path

Time Limit: 1s Memory Limit: 256MB

You are given a rectangular table 3 \times n. Each cell contains an integer. You can move from one cell to another if they share a side.Find such path from the upper left cell to the bottom right cell of the table that doesn't visit any of the cells twice, and the sum of numbers written in the cells of this path is maximum possible.

Input Format(From the terminal/stdin)

Input The first line contains an integer n (1 \le n \le 105) - the number of columns in the table.Next three lines contain n integers each - the description of the table. The j-th number in the i-th line corresponds to the cell aij (-109 \le aij \le 109) of the table.

Output Format(To the terminal/stdout)

Output Output the maximum sum of numbers on a path from the upper left cell to the bottom right cell of the table, that doesn't visit any of the cells twice.

Sample Input 1

Copy
3
1 1 1
1 -1 1
1 1 1
 \n
 · · \n
 ·  · \n
 · · \n

Sample Output 1

Copy
7
 \n

Sample Input 2

Copy
5
10 10 10 -1 -1
-1 10 10 10 10
-1 10 10 10 10
 \n
  ·  ·  ·  ·  \n
  ·  ·  ·  ·  \n
  ·  ·  ·  ·  \n

Sample Output 2

Copy
110
   \n

Hints

The path for the first example: 1982_1.png The path for the second example: 1982_2.png

Submit

请先 登录

© 2025 FAQs