Gas stations on a circular road
Statement
There are gas stations along a circular road, in this cyclic order. Station sells units of fuel and the stretch of road from to (with ) needs units of fuel. The total fuel available is at least the total fuel needed: . A car with an empty tank (and unlimited tank capacity) starts at one of the stations, takes all the fuel there, and drives on. Show that one can choose the starting station so that the car completes the full circle without ever running out of fuel.
Hint
Put and look at the partial sums . Where should the car start relative to the smallest partial sum?
Show solutionHide solution
Solution
Setup. Let and , so that . Let be an index minimising among . Start at station .
The car never runs out. The fuel left on arrival at the station after having driven stretches is for , and after wrapping around.
- For and : because is the minimum of (for we use ).
- After wrapping: .
All fuel-on-arrival amounts are non-negative, so the car never runs dry.
Remark. If the start is unique up to the stations where the minimum is attained. This is the cycle lemma.
Lesson. On a cycle, start right after the minimum of the prefix sums.