Two key observations:
If total gas < total cost, it's impossible. Otherwise, a solution exists.
If starting from station A you run out of gas at station B, then no station between A and B can be the answer (you'd run out even sooner).
Track cumulative balance. When it goes negative, reset the starting candidate to the next station. One pass suffices.