Your algorithm is correct.
Try to prove the following by induction on the number of stops stopped. After going through each water location, no other strategy could make fewer stops, and of those that made the same number of stops, no other strategy could leave you with more water.
At 0 stops, all strategies are equal, so it is trivial to prove the statement.
If you do not drink with this strategy, the result is easy to prove.
If you drink at a stop, from the fact that the statement was true at the previous stop, you can prove that either the other strategy made more stops for the last time (therefore, they do not stop at stops and cannot be ahead in the water, since you just got water), otherwise the other strategy was also to get water (otherwise they will remain in the water until the next stop).
This is enough to fill in the induction proof.
If you are struggling with the concept of what is required for formal proof, and how to do it, see How I make evidence ... I also wrote about my experience using this handout here .
source share