#T713. 【NOIP2008-S3】传纸条

【NOIP2008-S3】传纸条

Description

Xiao Yuan and Xiao Xuan are good friends and classmates who always have endless topics to discuss. During a team-building activity, their class was arranged into a matrix with m rows and n columns. Xiao Yuan and Xiao Xuan were placed at opposite ends of the matrix's diagonal, making direct conversation impossible. Fortunately, they could communicate by passing notes. The notes must be relayed through many classmates. Xiao Yuan sits at the top-left corner of the matrix, coordinates (1, 1), while Xiao Xuan sits at the bottom-right corner, coordinates (m, n). Notes passed from Xiao Yuan to Xiao Xuan can only move down or right, and notes passed from Xiao Xuan to Xiao Yuan can only move up or left.

During the activity, Xiao Yuan wanted to send a note to Xiao Xuan and also hoped for a reply. Each classmate could help relay the note, but only once—meaning if someone helped pass the note from Xiao Yuan to Xiao Xuan, they would not help again when the note is passed back from Xiao Xuan to Xiao Yuan, and vice versa.

Another thing to note is that each classmate has a varying level of willingness to help, represented by a natural number between 0 and 100 (note: Xiao Yuan and Xiao Xuan's willingness levels are undefined and are represented by 0 in the input). The higher the number, the more willing they are to help. Xiao Yuan and Xiao Xuan want to maximize the total willingness level of the classmates involved in both the outgoing and return paths of the note. Your task is to help them find such two paths.

Input Format

The first line contains two integers, m and n, separated by a space, indicating the class has m rows and n columns (1 ≤ m, n ≤ 50).

The next m lines form an m × n matrix, where the integer at the i-th row and j-th column represents the willingness level of the student sitting there. The n integers in each row are separated by spaces.

Output Format

A single line containing an integer, representing the maximum sum of the willingness levels of students involved in both the outgoing and return paths of the note.

```input1 3 3 0 3 9 2 8 5 5 7 0 ``` ```output1 34 ``` ## Source

NOIP2008-S3

(Note: NOIP stands for National Olympiad in Informatics in Provinces, which is a Chinese programming competition for secondary school students. The "S3" likely indicates this was the third problem in the senior division of the 2008 contest.)