Moving 4
Time limit2sMemory limit512 MB
Find the minimum total trash on a monotone path from (0, 0) to (N, M), where each right move costs A of its row and each down move costs B of its column.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
Junkyu is trapped in a maze of size . The maze is divided into rooms. The top-left room is , and the bottom-right room is . Junkyu is currently at and wants to reach . From , Junkyu can move through a door to or . Junkyu cannot leave the maze. Trash is now lying in the gaps between the doors. Whenever Junkyu moves from to , Junkyu must take all the trash in that gap, which is pieces. Moving from to requires taking pieces. Find the minimum amount of trash Junkyu must take to reach .
Input
The first line contains the maze size and (). The next line contains integers (). The next line contains integers ().
Output
Print the minimum amount of trash Junkyu must take to reach on the first line.