m rows and n columns of blocks; rows are numbered from 0 at the top and columns from 0 at the left. A courier stands at block start = [row, column] and lives at block home.
In one step the courier moves to a neighboring block up, down, left or right, without leaving the grid. Every step has a toll:
- a step up or down into a block in row r costs row_tolls[r];
- a step left or right into a block in column c costs col_tolls[c].
Here m = len(row_tolls) and n = len(col_tolls). Return the minimum cost for the courier to get home.start=[0, 2], home=[2, 0], row_tolls=[9, 1, 4], col_tolls=[3, 6, 2] → 14
Two steps down enter rows 1 and 2 for 1 + 4. Two steps left enter columns 1 and 0 for 6 + 3. Total 14, and any other order of the same steps costs the same.
start=[1, 1], home=[1, 1], row_tolls=[5, 5], col_tolls=[5, 5] → 0
The courier is already home, so there is nothing to pay.
start=[3, 0], home=[0, 1], row_tolls=[2, 0, 7, 1], col_tolls=[8, 5] → 14
start=[0, 2], home=[2, 0], row_tolls=[9, 1, 4], col_tolls=[3, 6, 2]
14
Run checks the first 3 tests in your browser. Submit checks all 77 tests on the server, hidden ones included.