#C8619. Maximum Points Path

    ID: 52621 Type: Default 1000ms 256MiB

Maximum Points Path

Maximum Points Path

You are given a grid of integers representing points. A player starts at the bottom-left cell and must reach the top-right cell. At each step the player can only move up or right to an adjacent cell. The goal is to maximize the total number of points collected along the path.

Formally, you are given an \( n \times m \) grid \( G \). The starting cell is \( G_{n-1,0} \) and the destination is \( G_{0,m-1} \). The allowed moves are from \( G_{i,j} \) to \( G_{i-1,j} \) (moving up) or to \( G_{i,j+1} \) (moving right), provided that the move stays within the grid. You are required to determine the maximum total points that can be attained along such a path.

Note: The indexing is defined such that the top row is the first row of the input and the bottom row is the last row.

inputFormat

The first line contains two space-separated integers \( n \) and \( m \), representing the number of rows and columns respectively.

The next \( n \) lines each contain \( m \) space-separated integers, representing the grid's rows in order from top to bottom.

outputFormat

Output a single integer: the maximum points that can be collected when moving from the bottom-left cell to the top-right cell.

## sample
3 3
0 2 4
3 1 1
2 0 5
12