Loading...
Loading...
Loading...
A delivery van crosses a city grid of R rows and C columns. Each block has a toll. The van starts at the top-left block and ends at the bottom-right block, moving only right or down, and pays the toll of every block it visits, including the first and the last. Print the smallest total toll.
Example
Input
3 3 1 3 1 1 5 1 4 2 1
Output
7
Route right, right, down, down costs 1 + 3 + 1 + 1 + 1 = 7.
Try the problem first. Open one hint at a time.
The cheapest cost to reach a block is its toll plus the smaller of the best cost from above and from the left.
Blocks on the top row or left column have only one way in.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor