FuelConsumption
SRM 217 · 2004-10-27 · by Olexiy
SRM 217 · 2004-10-27 · by Olexiy · Brute Force, Simple Math
Problem Statement
Problem Statement
You are taking your car on a long trip and have only a limited amount of fuel. You know how many liters of fuel your car uses per hour for certain speeds and you'd like to know how far a certain amount of fuel will take you when travelling at the optimal speed.
You will be given aint[] velocities and a int[] consumptions. velocities specifies a number of velocities in kilometers per hour. The ith element of consumptions is the amount of fuel (in milliliters) the car will consume in 1 hour, if your speed is equal to the ith element of velocities. In addition, you will be given an int fuel specifying the total amount of fuel in milliliters.
Your method should return a double , equal to the maximum distance that the car can travel (in kilometers) with the given amount of fuel, and travelling at a constant velocity equal to one of the elements of velocities.
You will be given a
Notes
- The returned value must be accurate to within a relative or absolute value of 1E-9.
Constraints
- velocities and consumptions will contain the same number of elements.
- velocities and consumptions will each contain between 1 and 50 elements, inclusive.
- Each element of velocities will be between 5 and 250, inclusive.
- Each element of consumptions will be between 1000 and 20000, inclusive.
- fuel will be between 100 and 50000, inclusive.
- velocities will not contain duplicate elements.
Examples
0)
{100}
{10000}
10000
Returns: 100.0
At 100 km/hour, you consume 10 liters of fuel per hour. You have 10 liters, so you can cover 100 kilometers.
1)
{70, 80, 90, 100, 60, 110}
{4000, 4000, 4000, 4000, 4000, 4000}
40000
Returns: 1100.0
Here, your car consumes the same amount of fuel at different velocities. In such cases the faster you drive the further you go.
2)
{250, 240, 230, 220, 210, 211}
{5000, 4500, 4000, 3500, 3000, 3000}
50000
Returns: 3516.6666666666665
3)
{5, 10, 20, 40, 80}
{1000, 2500, 6250, 9000, 18000}
47832
Returns: 239.16
4)
{5, 10, 20, 40, 80, 160}
{1000, 2500, 6250, 8000, 9500, 20000}
47832
Returns: 402.79578947368424
Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class FuelConsumption with a public method double maximalDistance(vector<int> velocities, vector<int> consumptions, int fuel) · 62 test cases · 2 s / 256 MB per case