Moving 3
InterviewTime limit2sMemory limit512 MB
A path from (0,0) to (N,M) using only down and right steps costs A[r] per down move and B[c] per right move; find the cheapest path.
- Level
Medium4 of 10
- Topics
- Greedy, Math, Prefix sum
- Solved
- No attempts yet
Problem
Jungyu is trapped in a maze of size . The maze is divided into rooms of size . The top-left room is and the bottom-right room is .
Jungyu is currently at and wants to move to . If Jungyu is at , he can move through a door to or . He cannot leave the maze.
This time there is trash in the gaps between the doors. So when moving from to or from to , he must take all the trash in the door gap. Moving from to takes pieces of trash, and moving to takes pieces of trash.
Find the minimum amount of trash Jungyu must take when he moves to .
Input
The first line gives the size of the maze, and . ()
The next line gives integers . ()
The next line gives integers . ()
Output
On the first line, print the amount of trash Jungyu must take when he moves to .