Regarding the logic used in the question

In the solution where the final part of the journey from the final fueling station to the town is considered, it is assumed that the truck will be at the last fuel stop at the end and then the distance is calculated. But will it always be the case?
What if we get enough fuel at the second stop itself to reach the town directly?

then that is the last fuel stop
for each stoppage, starting from farthest, if we can reach this stoppage with existing fuel, we push it in a priority queue (max heap in this case) for future use. If we cannot reach a particular stoppage, then we keep popping the queue and keep adding the amounts with currently available until we are able to reach current stoppage, and then pushing this value. This strategy ensures an optimal solution to reach a particular stoppage, as the priority queue will hold maximum capacities seen so far along the path, but not used yet.