GasStations
SRM 153 · 2003-07-01 · by lars2520
Problem Statement
More specifically, you will be given a
Notes
- Your solution need not be exactly correct to be evaluated as correct. As long as the relative error between your result and the true result is less than 1e-9, your result will be evaluated as correct.
Constraints
- distances and prices will contain the same number of elements.
- distances and prices will contain between 1 and 50 elements, inclusive.
- mpg will be between 1 and 1000, inclusive.
- tankSize will be between 1 and 1000, inclusive.
- tripLength will be between 2 and 10,000, inclusive.
- Each element of distances will be between 1 and tripLength-1, inclusive.
- Each element of prices will be between 50 and 20,000, inclusive.
- The trip will be possible.
{100,100}
{1000,1500}
20
10
300
Returns: 5000.0
The 10 gallon tank allows the car to go 200 miles on a full tank. So, in order to get from the station at 100 miles to the end of the trip at 300 miles, the tank has to be filled up at one of the gas stations after 100 miles. Clearly, we should fill it up at the cheaper one, and since we have gone 100 miles so far, we need to buy 5 gallons of gas, for 5,000 thousandths of a dollar.
{300,450,525}
{1659,1529,1439}
20
20
600
Returns: 15277.5
{300,450,525}
{1659,1439,1529}
20
20
600
Returns: 14940.0
{300,125,450,525}
{1659,1729,1439,1529}
20
20
600
Returns: 14940.0
{200}
{1000}
20
20
400
Returns: 0.0
{1500,4500}
{6000,8000}
80
40
6400
Returns: 282500.0
{1552,4580} {6773,8477} 79 40 5256
Submissions are judged against all 103 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class GasStations with a public method double tripCost(vector<int> dist, vector<int> price, int mpg, int tankSize, int tripLength) · 103 test cases · 2 s / 256 MB per case