|With gasoline prices as they are, driving can be expensive. By always driving at the optimal speed, however, you can minimize the cost. To do this, you must take 3 factors into account.|
1) The cost of your time. The faster you get where you are going, the more time you have to do other things.
2) The cost of speeding tickets. If you drive too fast, there is a risk that you will get a speeding ticket.
3) The cost of operating the vehicle (gasoline plus wear and tear).
You have collected some data pertaining to these three factors, and would now like to calculate the optimal speed to drive at. You will be given an int, costOfTime, representing the price at which you value an hour of your time. You will be given a String, tickets, indicating the cost and likelihood of getting a ticket at various speeds. Finally, you will be given a String, costPerMile, indicating the cost of operating your vehicle at different speeds.
Each element of tickets will be formatted as "SPEED PROBABILITY COST", indicating the probability per mile of receiving a ticket when travelling at the given speed. If you are travelling at a speed that does not correspond to any element of tickets, you should use linear interpolation to determine the probability of receiving a ticket (see examples). However, the cost of the ticket will be the cost of the ticket for the highest speed less than or equal to the travel speed. Note that if you are travelling at a speed less than the minimum SPEED in tickets, you cannot receive a ticket. Also, you should assume that each mile of road is independent and if you receive a ticket during one mile, that does not affect the probability of receiving a ticket during the next mile. Furthermore, you should assume that you will not receive more than one ticket in a single mile.
Each element of costPerMile will be formatted as "SPEED COST" indicating the cost per mile of travelling at a given speed. You should again interpolate to find the cost of speeds not in costPerMile. Your car cannot travel faster than the highest SPEED in costPerMile, and the smallest SPEED in costPerMile will always be 0.
You should find the speed that gives the lowest expected cost per mile and return that cost.
|-||You need not worry about the time that it takes to receive and deal with a ticket as this is already factored into the costs given to you.|
|-||Your return must have a relative or absolute error less than 1E-9.|
|-||costOfTime will be between 1 and 1000, inclusive.|
|-||tickets will contain between 1 and 50 elements, inclusive.|
|-||costPerMile will contain between 2 and 50 elements, inclusive.|
|-||Each element of tickets and costPerMile will contain at most 50 characters.|
|-||Each element of tickets will be formatted as "SPEED PROBABILITY COST".|
|-||Each element of costPerMile will be formatted as "SPEED COST".|
|-||Each SPEED in both inputs will be between 0 and 200, inclusive.|
|-||Each PROBABILITY will be between 0 and 0.1, inclusive.|
|-||Each COST in tickets will be between 1 and 1000000, inclusive.|
|-||Each COST in costPerMile will be between 0 and 5, exclusive.|
|-||All numbers in the inputs will be formatted as sequences of 1 or more digits, with an optional decimal point. They may contain extra leading or trailing zeros.|
|-||The smallest SPEED in costPerMile will be 0.|
|-||The largest SPEED in tickets will be greater than or equal to the largest SPEED in costPerMile.|
|-||Both String inputs will be sorted in ascending order by SPEED.|
|-||tickets will be sorted in non-descending order by COST and PROBABILITY.|
|-||No two SPEEDS in costPerMile will be within 1 of each other.|
|-||No two SPEEDS in tickets will be within 1 of each other.|