Given the travel cost of a cab is m rupees for first n hours per hour and then is x rupees per hour, given the total time of travel in minute the task is to find the total cost.
Note:If an hour starts then the traveller has to give the full cost for that hour.
Input: m = 50, n = 5, x = 67, mins 2927 Output: 3198 m = 50, n = 5, x = 67, Minutes travelled = 2927 Thus hours travelled = 49 Thus cost = 5 * 50 + (49-5) * 67 = 2927 Input: m = 50, n = 40, x = 3, mins = 35 Output: 50
Approach: First calculate the hours travelled by taking the ceiling of (minutes travelled)/60 as if we start an hour we have to pay the price of a full hour. Then we see that our hours calculated is less than equal to n or not if it is then we directly give the answer as m*hours travelled else answer is n * m + (hours_calculated – n) * x.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.