#C1912. Calculate Trip Fare with Surge Pricing
Calculate Trip Fare with Surge Pricing
Calculate Trip Fare with Surge Pricing
You are given information about a trip that includes the distance traveled, the start time, the start and end zones, a set of flat rate fares between certain zones, a base fare per kilometer, and a surge multiplier. Your task is to compute the total fare for the trip.
The computation is done as follows:
- If there is a flat rate fare for the pair of start and end zones (given in the flat fares table), then the total fare is that flat rate. That is, if \((s,e)\) appears in the table then \(\text{Fare} = \text{flat rate}\).
- Otherwise, compute a standard fare as \(\text{standard} = d \times b\), where \(d\) is the distance and \(b\) is the base fare per kilometer.
- If the trip starts during peak hours (i.e. if the hour part of the time \(t\) satisfies \(18 \leq hour < 21\)), then the fare is given by \(\text{Fare} = \text{standard} \times m\), where \(m\) is the surge multiplier.
- If the trip does not occur during peak hours, then \(\text{Fare} = \text{standard}\).
The final fare should be rounded to two decimal places.
Note: All formulas are represented in LaTeX format; for example, the standard fare is computed as \(d \times b\) and the surge-applied fare as \(d \times b \times m\)
inputFormat
The input is given through stdin in the following format:
d t s e n [flat fare entries] b m
- The first line contains an integer
d
(distance in kilometers), a stringt
representing the time in the format HH:MM, and two stringss
ande
representing the start and end zones. - The second line contains an integer
n
denoting the number of flat rate entries. - The next
n
lines each contain a flat fare entry with two strings (start zone and end zone) followed by a number representing the flat fare. - The following line contains an integer
b
, the base fare per kilometer. - The last line contains a floating-point number
m
, the surge multiplier.
All tokens are separated by spaces or line breaks.
outputFormat
Output a single line to stdout which is the total fare computed for the trip, rounded to two decimal places.
## sample10 19:30 A B
0
5
1.5
75.00