I never heard about this variation of the gas station problem. The statement is as follows:
There is just one road connecting the n+1 cities c0, …, cn consecutively. You want to go from c0 to cn stopping at most s times to fill the tank of the car. There are gas stations at the cities, but none on the roads. The length of each road is ℓ0, …, ℓn−1. Which is the minimum range for your car? Suppose that you start with a full tank.
This has to be done in something like nlogn
, because I already tried the n^2
approach and is not good. I don't know how to decide if I should refill at some point or not.
For this inp:
5 0
100 300 500 200 400
5 1
100 300 500 200 400
5 2
100 300 500 200 400
5 3
100 300 500 200 400
5 4
100 300 500 200 400
The output should be: 1500 900 600 500 500
(Consider that the input is a sequence of n
and s
, followed by n
naturals that represents l_i
.