A rally truck has to cover target kilometres of desert track, using one litre per kilometre, and sets off with fuel litres. Supply depots along the track are listed in stations as [position, litres], sorted by position; stopping at a depot loads all of its litres (the jerrycan rack never fills up). Arriving at a depot or at the finish with exactly zero litres left is fine. Return the fewest depot stops that get the truck to the finish, or -1 if it cannot get there.
Examples
Input: target = 120, fuel = 25, stations = [[15, 20], [30, 50], [50, 10], [80, 60], [90, 5]]
Output: 3
Explanation: Stop at 15 (the truck can now reach kilometre 45), at 30 (reach 95) and at 80
(reach 155 >= 120).
Input: target = 50, fuel = 50, stations = []
Output: 0
Constraints
1 <= target <= 10**9,0 <= fuel <= 10**9,0 <= len(stations) <= 5 * 10**4.0 < position < target,1 <= litres <= 10**9; positions strictly increase.- Target complexity: O(n log n).
Goals
- Defer the decision of where to stop until a stop becomes necessary
- Use a max-heap of passed stations to pick the most valuable one