Cheapest Path Through the Grid
Walk from the top-left to the bottom-right cell moving only right or down, paying each visited cell's cost. Minimize the total.
Input: the first line has N and M; the next N lines each have M non-negative integers.
Output: the minimum path cost.
Constraints:
- 1 ≤ N, M ≤ 1000
- 0 ≤ cost ≤ 100
Sample Tests
Input 1
2 3 1 3 1 1 5 1
Output 1
6
Input 2
1 1 7
Output 2
7
Discussion (opens after you solve — no spoilers before)
No comments yet.