# Total money to be paid after traveling the given number of hours

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.

**Examples:**

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:

## C++

`// CPP implementation of the above approach ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `int` `main(){ ` ` ` ` ` `float` `m=50, n=5, x=67, h=2927; ` ` ` ` ` `// calculating hours travelled ` ` ` `int` `z = (` `ceil` `(h / 60*1.0)); ` ` ` `if` `(z <= n) ` ` ` `cout<<z * m; ` ` ` `else` ` ` `cout<<n * m+(z-n)*x; ` ` ` ` ` `return` `0; ` `} ` ` ` `// This code is contributed by Sanjit_Prasad ` |

*chevron_right*

*filter_none*

## Java

`// Java implementation of the above approach ` ` ` `import` `java.io.*; ` ` ` `class` `GFG { ` ` ` ` ` ` ` `public` `static` `void` `main (String[] args) { ` ` ` `float` `m=` `50` `, n=` `5` `, x=` `67` `, h=` `2927` `; ` ` ` ` ` `// calculating hours travelled ` ` ` `int` `z = (` `int` `)(Math.ceil(h / ` `60` `*` `1.0` `)); ` ` ` `if` `(z <= n) ` ` ` `System.out.println(z * m); ` ` ` `else` ` ` `System.out.println(n * m+(z-n)*x); ` ` ` `} ` `} ` ` ` `// This code is contributed by shs ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 implementation of the above approach ` ` ` `import` `math as ma ` `m, n, x, h ` `=` `50` `, ` `5` `, ` `67` `, ` `2927` ` ` `# calculating hours travelled ` `z ` `=` `int` `(ma.ceil(h ` `/` `60` `)) ` `if` `(z <` `=` `n): ` ` ` `print` `(z ` `*` `m) ` `else` `: ` ` ` `print` `(n ` `*` `m` `+` `(z` `-` `n)` `*` `x) ` |

*chevron_right*

*filter_none*

## C#

`// C# implementation of the above approach ` ` ` `using` `System; ` ` ` `class` `GFG { ` ` ` ` ` ` ` `public` `static` `void` `Main () { ` ` ` `float` `m=50, n=5, x=67, h=2927; ` ` ` ` ` `// calculating hours travelled ` ` ` `int` `z = (` `int` `)(Math.Ceiling((h / 60*1.0))); ` ` ` `if` `(z <= n) ` ` ` `Console.WriteLine(z * m); ` ` ` `else` ` ` `Console.WriteLine(n * m+(z-n)*x); ` ` ` `} ` `} ` ` ` `// This code is contributed by anuj_67.. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP implementation of the ` `// above approach ` `$m` `= 50; ` `$n` `= 5; ` `$x` `= 67; ` `$h` `= 2927; ` ` ` `# calculating hours travelled ` `$z` `= (int)(` `ceil` `(` `$h` `/ 60)); ` `if` `(` `$z` `<= ` `$n` `) ` ` ` `print` `(` `$z` `* ` `$m` `); ` `else` ` ` `print` `(` `$n` `* ` `$m` `+ (` `$z` `- ` `$n` `) * ` `$x` `); ` ` ` `// This code is contributed by mits ` `?> ` |

*chevron_right*

*filter_none*

**Output:**

3198

## Recommended Posts:

- Number of hours after which the second person moves ahead of the first person if they travel at a given speed
- Find the total number of composite factor for a given number
- Find the total Number of Digits in (N!)N
- Count total number of digits from 1 to n
- Total number of divisors for a given number
- Total number of non-decreasing numbers with n digits
- Total number of different staircase that can made from N boxes
- Total number of subsets in which the product of the elements is even
- Total number of ways to place X and Y at n places such that no two X are together
- Program for converting hours into minutes and seconds
- Minimum number of letters needed to make a total of n
- Total number of Spanning trees in a Cycle Graph
- Find out the minimum number of coins required to pay total amount
- Program to find total number of edges in a Complete Graph
- Count the total number of squares that can be visited by Bishop in one move

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.