Loading...
Loading...
Loading...
A truck starts with f units of fuel and must travel to a destination d units away, using one unit per unit of distance. Along the road, stations sit at given distances and each holds a stock of fuel that the truck takes whole when it stops. Print the fewest stops needed to reach the destination, or -1 if it cannot.
Example 1
Input
100 10 4 10 60 20 30 30 30 60 40
Output
2
Example 2
Input
100 1 0
Output
-1
Try the problem first. Open one hint at a time.
Reach as far as you can, and note every station you pass.
When the fuel runs out before the destination, take the largest stock among the stations you passed. A max-heap does this.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor