#P2836. Minimum Fuel and Food Cost Estimation
Minimum Fuel and Food Cost Estimation
Minimum Fuel and Food Cost Estimation
An American travel agent is often asked to estimate the minimum cost for fuel and food when driving from one city to another. The journey has a list of gas stations along the usual route. For each gas station, its position (in miles from the start) and the current price per gallon of gasoline (in dollars) are provided.
The driver follows these simplified rules:
- The driver starts with a full tank of fuel with capacity \(C\) gallons.
- While driving, the driver uses only the exact amount of fuel required to reach the next station or the destination (i.e. no extra "safety margin"). The car's fuel efficiency is \(E\) (miles per gallon).
- When arriving at a gas station, if the remaining fuel is at least \(\frac{C}{2}\) and is enough to reach the next station (or the destination if there is no further station), the driver never stops for fuel.
- If the fuel left is less than half of the tank, or it is insufficient to reach the next station/destination, then the driver stops and fills the tank completely.
- At every stop the driver also spends \($2.00\) on food (fast food and candy).
- When refueling, the driver buys exactly what is needed to fill the tank (i.e. \(C - \text{fuel remaining}\)). Payment at each stop is rounded to the nearest cent (i.e. standard rounding where \(1\) dollar equals \(100\) cents).
Your task is to write a program that estimates the minimum total amount the driver has to pay for fuel and food over the journey.
Input Format
The input begins with a single line containing three numbers: \(C\) (the fuel tank capacity in gallons), \(E\) (the fuel efficiency in miles per gallon), and \(D\) (the distance to the destination in miles).
The next line contains an integer \(N\) indicating the number of gas stations. This is followed by \(N\) lines, each containing two numbers representing the position of a gas station (in miles from the start) and the price per gallon at that station (in dollars). The gas stations are given in increasing order of their position.
Output Format
Output the minimum total cost (in dollars) that the driver spends on fuel and food during the trip. The answer must be printed as a floating-point number rounded to two decimal places.
Note
You may assume that the journey can always be completed under the given conditions.
inputFormat
The first line contains three numbers: \(C\) \(E\) \(D\) (tank capacity in gallons, fuel efficiency (miles per gallon), and destination distance in miles respectively).
The second line contains an integer \(N\) indicating the number of gas stations.
This is followed by \(N\) lines, each with two numbers: the position (in miles) of the gas station and the price per gallon (in dollars).
outputFormat
Output the minimum total cost in dollars (including fuel cost and food cost) rounded to two decimal places.
sample
50 10 600
3
150 2.5
300 2.7
450 2.6
83.00