Racing
I-Will-Windra has entered a racing contest! The racetrack can be represented as two arrays of integers a and b, both of length n. When I-Will-Windra is at position i, they can jump a[i] positions to the left or right, assuming it is within the bounds of the array. Furthermore, this move costs them b[i].
As I-Will-Windra's FIT2004 tutor, you want to help them. Given starting positions x and y, what is the minimum cost by which I-Will-Windra can get from x to y? If this is not possible, output -1 instead.
Input
The first line of input will consist of three integers, x y and z.
The next two lines will each consist of n integers, representing a and b respectively.
Output
The output should consist of a single integer, the minimum cost or -1 if it is impossible.
Constraints
- 2≤n≤105
- 0≤x,y≤n−1
- 1≤a[i]≤n
- 1≤b[i]≤30
Example 1
5 4 2
3 3 1 3 2
533 776 812 489 523
523
Explanation
This can be completed in one jump, from index 4 to index 2 (of cost 523).
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.