Alice wants to play a matrix fetching game on a matrix, where the elements of the matrix are all non-negative integers. The rules of the game are as follows:
Alice has round of fetching.
For each fetching, she needs to take away one element from each row of the matrix.
Each element taken at a time can only be the first or last one of the row.
After each fetching, she will get a score. The score is the sum of all scores earned from fetching each row. The scores earned from each row is equal to , where is the value of the element taken, and is the round of fetching (labeled from to ).
After rounds, all of the elements of the matrix will be taken, and the score earned from each fetching will be added to get the final score.
Your goal is to find the optimal strategy for Alice to get maximum final score possible.
How to submit:
The pastebin below has inputs. Each input has the format:
Two numbers , the number of rows and columns of the matrix.
numbers, the values of each element of the matrix.
You should output: A number , the maximum final score Alice can get.
Then submit the sum of all of the outputs.
Input restrictions:
Input : .
Input : .
This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try
refreshing the page, (b) enabling javascript if it is disabled on your browser and,
finally, (c)
loading the
non-javascript version of this page
. We're sorry about the hassle.