
Price of ‘Petrol’ car = ‘780000’, the maintenance cost of ‘Petrol’ car per month = ‘500’, number of kilometers a ‘Petrol’ car can run in one liter = ’35’, price of ‘Petrol’ per liter = ‘75’ and number of kilometers a ‘Petrol’ car can run in a month = ‘145’.
Similar details are given for ‘Diesel’ car, price of ‘Diesel’ car = ‘850000’, the maintenance cost of ‘Diesel’ car per month = ‘1000’, number of kilometers a ‘Diesel’ car can run in a one-liter = ’30’, price of ‘Diesel’ per liter = ‘80’ and number of kilometers a ‘Diesel’ car can run in a month = ‘200’.
Then the ‘Petrol’ car will be more efficient, so we will print the integer ‘0’.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘2*T’ lines represent the ‘T’ test cases.
The first line of each test case contains the 5 space-separated integers which denote the price of a ‘Petrol’ car, maintenance cost of ‘Petrol’ car per month, number of kilometers a ‘Petrol’ car runs in one liter, price of ‘Petrol’ per liter, number of kilometers run a ‘Petrol’ car per month.
The second line of each test case contains the 5 space-separated integers which denote the price of a ‘Diesel’ car, the maintenance cost of ‘Diesel’ car per month, the number of kilometers a ‘Diesel’ car runs in one liter, the price of ‘Diesel’ per liter, number of kilometers run a ‘Diesel’ car per month.
In the main function ‘mostCostEfficientCar’, ‘petrolCar’, ‘dieselCar’ are two objects of ‘Car’ class, and allow to access all parameters (priceOfCar, maintenanceCostPerMonth, numberOfkilemeterCarRunInOneLiter, pricePerLiter, numberOfKilometerCarRunInaMonth) by pointer.
For each test case, print ‘0’, ‘1’, and ‘-1’ accordingly, if your answer is ‘Petrol’ car then print ‘0’, if your answer is ‘Diesel’ car then print ‘1’, if both the cars ( ‘Petrol’ and ‘Diesel’) are efficient then print ‘-1’.
You are not required to print the output explicitly, it has already been taken care of. Just implement the function.
1 <= T <= 10^5
1 <= priceOfCar, maintenanceCostPerMonth, numberOfkilemeterCarRunInOneLiter, pricePerLiter, numberOfKilometerCarRunInaMonth <= 10^9
Where ‘T’ is the total number of test cases.
Time Limit: 1 sec
Approach: The basic idea is that, find the total cost of a ‘Petrol’ car and ‘Diesel’ car for 6 months.
Algorithm is as follows:
Pair Product Div by K
Pair Product Div by K
Merge Two Sorted Arrays Without Extra Space
Merge Two Sorted Arrays Without Extra Space
Co-Prime
First Digit One
Special Digit Numbers