#C11514. Minimum Path Sum

    ID: 40839 Type: Default 1000ms 256MiB

Minimum Path Sum

Minimum Path Sum

You are given a grid of non-negative integers with dimensions \(m \times n\). Your task is to find a path from the top-left corner to the bottom-right corner such that the sum of the numbers along the path is minimized. You can only move either down or right at any point in time.

This is a classic dynamic programming problem where you need to compute the cumulative minimal path cost, taking the minimum of moving right or down at each step.

inputFormat

The first line contains two integers \(m\) and \(n\) representing the number of rows and columns in the grid, respectively. The following \(m\) lines each contain \(n\) space-separated integers, which represent the cost of each cell in the grid.

outputFormat

Output a single integer which is the minimum path sum from the top-left corner to the bottom-right corner of the grid.

## sample
3 3
1 3 1
1 5 1
4 2 1
7

</p>