#C8031. Taco: Maximum Grid Points

    ID: 51969 Type: Default 1000ms 256MiB

Taco: Maximum Grid Points

Taco: Maximum Grid Points

You are given one or more grids. Each grid consists of (n) rows and (m) columns of integers. Starting at the top-left cell, your goal is to reach the bottom-right cell by only moving right or down. At each step, you add the integer value of the visited cell. Your task is to determine the maximum points you can collect across the grid. The dynamic programming recurrence used to solve the problem is given by (dp[i][j] = grid[i][j] + \max(dp[i-1][j], dp[i][j-1])), where (dp[i][j]) represents the maximum points to reach cell ((i, j)).

inputFormat

The input consists of multiple test cases. Each test case begins with two integers (n) and (m) representing the number of rows and columns, respectively. This is followed by (n) lines each containing (m) space-separated integers representing the grid. The input terminates with a line containing '0 0', which should not be processed.

outputFormat

For each test case, output the maximum points that can be collected from the top-left to the bottom-right cell. Each answer should be printed on a new line.## sample

3 3
1 2 3
4 5 6
7 8 9
0 0
29

</p>