#K12686. Minimum Difficulty Path
Minimum Difficulty Path
Minimum Difficulty Path
You are given a grid of integers where each integer represents the difficulty of stepping on that cell. You start at the top-left corner (0,0) and your goal is to reach the bottom-right corner (m-1, n-1) with the minimum total difficulty. You are allowed to move in four directions: up, down, left, and right.
If you traverse a path consisting of cells \( (x_0,y_0), (x_1,y_1), \ldots, (x_k,y_k) \), then the total difficulty is defined as:
\( \sum_{i=0}^{k} grid[x_i][y_i] \)
Your task is to compute the minimum possible sum of difficulties to travel from the starting point to the destination.
inputFormat
The first line contains two integers m and n separated by a space, representing the number of rows and columns in the grid, respectively.
Each of the next m lines contains n space-separated integers. The j-th integer in the i-th line represents the difficulty of the cell at position \( (i, j) \).
outputFormat
Output a single integer which is the minimum total difficulty required to reach the bottom-right corner from the top-left corner.
## sample3 3
1 3 1
1 5 1
4 2 1
7
</p>