|
Tour de Manhattan
Manhattan is a beautiful but dangerous part of New York. The urban planners of this area decided that Manhattan should be built up with parallel streets and perpendicular avenues, so that it looks kinda like a chessboard. This by itself is a very neat attraction, however we as tourists decided that we should travel through the area and check as many attractions as we could possibly can. However since age was not so kind to us, we need to think twice which way we are choosing, since our old joints cannot handle turnbacks. This means that from our starting point (which is the "top left" cell of the board) we can only travel rightway and bottomway. Before our stroll we gained the following discoveries/rules:
- Manhattans' map is a rectangle which is divided into cells. We start from the top left (0,0) indexed cell.
- Every cell has an integer value. The higher the value the more interesting the attraction at that point is.
- Moving is done one step at a time either to the right cell (so our x coordinate increases by one) or to the one directly below us (so our y coordinate increases by one).
- Our aim is to reach the bottom right cell and have the largest possible sum of values there.
Since during our younger years we were quite interested in algorithm-theory, we were able to find out that reaching the optimal profit is easy:
- The value of the starting cell is the value there itself.
- Every other cells' value in the 0th row is the sum of the cells' value directly left from it and the cells' own value.
- Every other cells' value in the 0th column is the sum of the cells' value directly above it and the cells' own value.
- Every other cells' value can be calculated by max(value of the cell directly above,value of the cell directly to the left)+the cells' own value.
Our task however is much more complex than simply creating this table: we need to tell stories to our grandchildren about our adventure, so your task is to determine which cells should we take get the highest profit at the bottom right cell by using the ruleset above (so technically to "draw" a route).
Input
The input contains three units:
- The first line is an n positive integer which tells us the number of rows of the table.
- The second line is an m positive integer which tells us the number of columns of the table.
- Each of the following n lines contain m integers separated by a single space character which tells us the value of the "attractions".
Output
The output is one single line which tells us the optimal route from the starting 0,0 cell to the bottom right n-1,m-1 cell. This optimal route is given by the ruleset above and you do not need to verify its optimality. The output should contain the row and column indices in a way that the indices of one cell is separated by a single comma (,) character, and the cells are separated by a single space character. Example for a route with n=6, m=5: 0,0 0,1 1,1 2,1 3,1 4,1 4,2 4,3 4,4 5,4
Restrictions
- n and m are at most 200
- every value inside each cell is between -100 and +100
- you can assume that the ruleset above gives you the highest profit in the bottom right cell
- every starting table will be constructed such that there is only one optimal route
Example
|
|