Google | Onsite | Minimum Cost to Travel
Anonymous User
5900

A car has to travel from point A to point B.
The fuel capacity of the tank of the car is V units.
Initially, the tank is completely filled.

There are m Gas Stations at points D1, D2, .... Dm on the way between A and B and the cost of fuel at each Gas Station is given by a price array P, where Pi = price of fuel per unit at Gas Station i. Each Gas Station is having unlimited quantity of fuel and you may fill as much as you want (obviously <=V).

Return the minimum cost to travel from point A to point B.

The function is as follows:

int minimumCost(int V, int A, int B, vector<int> dis, vector<int> price){

}

I used a min heap to store the (price, dis) of each gas station and then pick the gas station from where the tank should be re-filled. But, I was not able to finish the solution.

Comments (20)