A car travels from a starting position to a destination which is target miles east of the starting position.
Along the way, there are gas stations.  Each station[i] represents a gas station that is station[i][0] miles east of the starting position, and has station[i][1] liters of gas.
The car starts with an infinite tank of gas, which initially has startFuel liters of fuel in it.  It uses 1 liter of gas per 1 mile that it drives.
When the car reaches a gas station, it may stop and refuel, transferring all the gas from the station into the car.
What is the least number of refueling stops the car must make in order to reach its destination?  If it cannot reach the destination, return -1.
Note that if the car reaches a gas station with 0 fuel left, the car can still refuel there.  If the car reaches the destination with 0 fuel left, it is still considered to have arrived.
 

Example 1:
Input: target = 1, startFuel = 1, stations = []
Output: 0
Explanation: We can reach the target without refueling.


Example 2:
Input: target = 100, startFuel = 1, stations = [[10,100]]
Output: -1
Explanation: We can't reach the target (or even the first gas station).


Example 3:
Input: target = 100, startFuel = 10, stations = [[10,60],[20,30],[30,30],[60,40]]
Output: 2
Explanation: 
We start with 10 liters of fuel.
We drive to position 10, expending 10 liters of fuel.  We refuel from 0 liters to 60 liters of gas.
Then, we drive from position 10 to position 60 (expending 50 liters of fuel),
and refuel from 10 liters to 50 liters of gas.  We then drive to and reach the target.
We made 2 refueling stops along the way, so we return 2.

 
Note:

1 <= target, startFuel, stations[i][1] <= 10^9
0 <= stations.length <= 500
0 < stations[0][0] < stations[1][0] < ... < stations[stations.length-1][0] < target

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'class Solution:\n    def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:\n        if startFuel >= target: return 0\n        if not stations: return -1\n        data = []\n\n        for k in range(len(stations)):\n            data.append([stations[k][0]-(stations[k-1][0] if k > 0 else 0), stations[k][1]])\n        data.append([target-stations[-1][0],0])\n\n        # data is a list of [how far you have to go to reach station x from previous station, how much gas you get at station x]\n        # we add a \\"station\\" at the target with 0 gas... we want to see if we can reach this spot\n        \n        # let\'s check if we made all stops, we could make it\n        tot = startFuel\n        for dist,gas in data:\n            tot -= dist            \n            if tot < 0: return -1\n            tot += gas\n        \n        N = len(data)\n        \n        # maxFuel represents how much fuel you could have at this station \n        maxFuel = [float(\'-inf\')] * N  \n        \n        # let\'s start with 0 stops\n        tot = startFuel\n        for k in range(N):\n            dist,_ = data[k]\n            tot -= dist\n            if tot < 0: break            \n            maxFuel[k] = tot\n            \n        #print(\'after 0 stops\',maxFuel)\n            \n        # let\'s do 1 stop separately as well\n        nextMaxFuel = [float(\'-inf\')] * N\n        nextMaxFuel[0] = maxFuel[0] + data[0][1]\n        for k in range(1,N):\n            dist,gas = data[k]\n            if maxFuel[k] != float(\'-inf\'):\n                nextMaxFuel[k] = maxFuel[k]+gas\n            if nextMaxFuel[k-1] >= dist:\n                nextMaxFuel[k] = max(nextMaxFuel[k], nextMaxFuel[k-1]-dist)\n            if nextMaxFuel[k] == float(\'-inf\'):\n                break\n        \n        if nextMaxFuel[-1] >= 0: return 1\n        \n        maxFuel = nextMaxFuel\n        \n        #print(\'after 1 stop\',maxFuel)\n\n        for nStops in range(2, N+1):\n            nextMaxFuel = [float(\'-inf\')] * N            \n            for k in range(nStops-1, N):\n                dist,gas = data[k]\n                if maxFuel[k-1] != float(\'-inf\') and maxFuel[k-1] >= dist: # i.e., we could make it to the station with nStops-1\n                    nextMaxFuel[k] = maxFuel[k-1] - dist + gas\n                if nextMaxFuel[k-1] >= dist:\n                    nextMaxFuel[k] = max(nextMaxFuel[k], nextMaxFuel[k-1]-dist) # i.e., don\'t stop at this station, use prior result\n                if nextMaxFuel[k] == float(\'-inf\'):\n                    break # we won\'t be able to get to later stations either\n            #print(\'after\',nStops,\'stops\',nextMaxFuel)\n            if nextMaxFuel[-1] >= 0: return nStops\n            maxFuel = nextMaxFuel\n           \n        return -1\n            \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'minRefuelStops'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 6752