Walking Is Annoying
InterviewTime limit1sMemory limit1024 MB
Given N rickshaws at sorted positions, each covering a range to its right, find the minimum number of transfers to reach point M without walking.
- Level
Medium6 of 10
- Topics
- Greedy, BFS, Array, Two pointers
- Solved
- No attempts yet
Problem
On a line there are points , each with a rickshaw puller who can carry a passenger up to units. That is, the puller at takes the passenger to one of , , , , .
Hyeonsol, the laziest person in the world when it comes to walking, wants to reach the destination without walking, riding rickshaws only. Hyeonsol is already on the first rickshaw. Find the minimum number of rickshaw transfers needed to reach the destination.
Input
The first line gives and , separated by a space. (, )
The second line gives the positions , , , of the points, separated by spaces in increasing order. (, )
The third line gives the maximum travel distances , , , of the rickshaw pullers, separated by spaces in that order. ()
Output
Print the minimum number of rickshaw transfers Hyeonsol needs to reach the destination without walking. If the destination cannot be reached, print -1.