#C11621. Maximum Points in a Grid Traversal

    ID: 40958 Type: Default 1000ms 256MiB

Maximum Points in a Grid Traversal

Maximum Points in a Grid Traversal

You are given a grid with R rows and C columns. Each cell of the grid contains a non-negative integer representing the points you can collect.

Your task is to compute the maximum number of points you can collect by starting from the top-left cell (0, 0) and reaching the bottom-right cell (R-1, C-1). When moving through the grid, you can only move either right or down at each step.

The problem can be formulated in terms of dynamic programming. Let \(dp[i][j]\) be the maximum points that can be collected when reaching cell \((i, j)\). Then, the recurrence relation is given by:

\(dp[i][j] = \max(dp[i-1][j],\ dp[i][j-1]) + grid[i][j]\) for \(i, j \geq 1\).

You are required to implement a solution that reads input from stdin and writes the result to stdout.

inputFormat

The first line contains two integers R and C separated by a space, representing the number of rows and columns respectively.

The next R lines each contain C space-separated integers, representing the points in each cell of the grid.

outputFormat

Output a single integer which is the maximum number of points that can be collected from the top-left cell to the bottom-right cell.

## sample
3 3
5 3 2
1 2 0
4 6 1
17