#K43572. Minimum Path Sum in a Grid
Minimum Path Sum in a Grid
Minimum Path Sum in a Grid
You are given an m x n grid filled with non-negative integers. Your task is to compute the minimum sum of values along a path from the top-left cell to the bottom-right cell. At every step, you can only move either down or right.
The minimal path sum is defined mathematically as:
$$ \min_{\text{path}} \sum_{(i,j) \in \text{path}} grid_{i,j} $$
The grid is provided via standard input where the first line contains two integers m and n (the number of rows and columns respectively), followed by m lines each containing n integers.
inputFormat
The input is given via standard input (stdin) in the following format:
m n row1_value1 row1_value2 ... row1_value_n row2_value1 row2_value2 ... row2_value_n ... rowm_value1 rowm_value2 ... rowm_value_n
Here, the first line contains two space-separated integers m and n. Each of the next m lines contains n non-negative integers representing the grid.
outputFormat
The output is a single integer printed to standard output (stdout), which represents the minimum sum of values along a valid path from the top-left corner to the bottom-right corner.
## sample1 1
1
1