#K80377. Maximum Food Consumption in a Grid
Maximum Food Consumption in a Grid
Maximum Food Consumption in a Grid
You are given a grid of non-negative integers with n rows and m columns. Each cell in the grid represents the amount of food available at that position. Starting from the top-left cell, you must move to the bottom-right cell, and you are only allowed to move either right or down at any time.
Your task is to compute the maximum total amount of food that can be collected along a path from the top-left to the bottom-right cell. The maximum food is the sum of the values of the visited cells along the optimal path.
Constraints:
- 1 ≤ n, m ≤ 1000
- Each cell value is a non-negative integer.
The optimal solution can be achieved using dynamic programming.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains two integers n and m, representing the number of rows and columns, respectively.
- This is followed by n lines, each containing m integers separated by spaces, representing the grid.
outputFormat
Output a single integer: the maximum total food that can be collected, printed to standard output (stdout).
## sample3 3
1 3 1
1 5 1
4 2 1
12