Given n number of cashiers exchanging the money. At the moment, cashier had number of people in front of him. The person in the line to cashier had notes.

Find, how much early can one exchange his notes.

Time taken by the cashiers:

- The cashier took 5 seconds to scan a single note.
- After the cashier scanned every note for the customer, he took 15 seconds to exchange the notes.

Examples:

Input : n = 5

k[] = 10 10 10 10 10

m1[] = 6 7 8 6 8 5 9 8 10 5

m2[] = 9 6 9 8 7 8 8 10 8 5

m3[] = 8 7 7 8 7 5 6 8 9 5

m4[] = 6 5 10 5 5 10 7 8 5 5

m5[] = 10 9 8 7 6 9 7 9 6 5

Output : 480

Explanation:The cashier takes 5 secs for every note of each customer, therefore add 5*m[i][j]. Each cashier spends 15 seconds for every customer, therefore add 15*k[] to the answer. The minimum time obtained after calculating the time taken by each cashier is our answer. Cashier m4 takes the minimum time i.e. 480.Input : n = 1

k[] = 1

m1[] = 100

Output : 515

**Approach :** Calculate the total time for every cashier and minimum time obtained among all the cashier’s time is the desired answer.

Below is the implementation of above approach:

## C++

`// CPP code to find minimum ` `// time to exchange notes ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to calculate minimum ` `// time to exchange note ` `void` `minTimeToExchange(` `int` `k[], ` `int` `m[][10], ` ` ` `int` `n) ` `{ ` ` ` `int` `min = INT_MAX; ` ` ` ` ` `// Checking for every cashier ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `{ ` ` ` `// Time for changing the notes ` ` ` `int` `temp = k[i] * 15; ` ` ` ` ` `// Calculating scanning time ` ` ` `// for every note ` ` ` `for` `(` `int` `j = 0; j < k[i]; j++) ` ` ` `{ ` ` ` `temp += m[i][j] * 5; ` ` ` `} ` ` ` ` ` `// If value in temp is minimum ` ` ` `if` `(temp < min) ` ` ` `min = temp; ` ` ` `} ` ` ` ` ` `cout << min; ` `} ` ` ` `// Driver function ` `int` `main() ` `{ ` ` ` `// number of cashiers ` ` ` `int` `n = 5; ` ` ` ` ` `// number of customers with ` ` ` `// each cashier ` ` ` `int` `k[] = {10, 10, 10, 10, 10}; ` ` ` ` ` `// number of notes with each customer ` ` ` `int` `m[][10] = {{6, 7, 8, 6, 8, 5, 9, 8, 10, 5}, ` ` ` `{9, 6, 9, 8, 7, 8, 8, 10, 8, 5}, ` ` ` `{8, 7, 7, 8, 7, 5, 6, 8, 9, 5}, ` ` ` `{6, 5, 10, 5, 5, 10, 7, 8, 5, 5}, ` ` ` `{10, 9, 8, 7, 6, 9, 7, 9, 6, 5}}; ` ` ` ` ` `// Calling function ` ` ` `minTimeToExchange(k, m, n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java code to find minimum time to exchange ` `// notes ` `import` `java.io.*; ` ` ` `public` `class` `GFG { ` ` ` ` ` `// Function to calculate minimum ` ` ` `// time to exchange note ` ` ` `static` `void` `minTimeToExchange(` `int` `[]k, ` ` ` `int` `[][]m, ` `int` `n) ` ` ` `{ ` ` ` ` ` `int` `min = Integer.MAX_VALUE; ` ` ` ` ` `// Checking for every cashier ` ` ` `for` `(` `int` `i = ` `0` `; i < n; i++) ` ` ` `{ ` ` ` `// Time for changing the notes ` ` ` `int` `temp = k[i] * ` `15` `; ` ` ` ` ` `// Calculating scanning time ` ` ` `// for every note ` ` ` `for` `(` `int` `j = ` `0` `; j < k[i]; j++) ` ` ` `{ ` ` ` `temp += m[i][j] * ` `5` `; ` ` ` `} ` ` ` ` ` `// If value in temp is minimum ` ` ` `if` `(temp < min) ` ` ` `min = temp; ` ` ` `} ` ` ` ` ` `System.out.println(min); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `static` `public` `void` `main (String[] args) ` ` ` `{ ` ` ` ` ` `// number of cashiers ` ` ` `int` `n = ` `5` `; ` ` ` ` ` `// number of customers with ` ` ` `// each cashier ` ` ` `int` `[]k = {` `10` `, ` `10` `, ` `10` `, ` `10` `, ` `10` `}; ` ` ` ` ` `// number of notes with each customer ` ` ` `int` `[][]m = { ` ` ` `{` `6` `, ` `7` `, ` `8` `, ` `6` `, ` `8` `, ` `5` `, ` `9` `, ` `8` `, ` `10` `, ` `5` `}, ` ` ` `{` `9` `, ` `6` `, ` `9` `, ` `8` `, ` `7` `, ` `8` `, ` `8` `, ` `10` `, ` `8` `, ` `5` `}, ` ` ` `{` `8` `, ` `7` `, ` `7` `, ` `8` `, ` `7` `, ` `5` `, ` `6` `, ` `8` `, ` `9` `, ` `5` `}, ` ` ` `{` `6` `, ` `5` `, ` `10` `, ` `5` `, ` `5` `, ` `10` `, ` `7` `, ` `8` `, ` `5` `, ` `5` `}, ` ` ` `{` `10` `, ` `9` `, ` `8` `, ` `7` `, ` `6` `, ` `9` `, ` `7` `, ` `9` `, ` `6` `, ` `5` `}}; ` ` ` ` ` `// Calling function ` ` ` `minTimeToExchange(k, m, n); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 code to find minimum ` `# time to exchange notes ` `from` `sys ` `import` `maxsize ` ` ` `# Function to calculate minimum ` `# time to exchange note ` `def` `minTimeToExchange(k, m, n): ` ` ` `minn ` `=` `maxsize ` ` ` ` ` `# Checking for every cashier ` ` ` `for` `i ` `in` `range` `(n): ` ` ` ` ` `# Time for changing the notes ` ` ` `temp ` `=` `k[i] ` `*` `15` ` ` ` ` `# Calculating scanning time ` ` ` `# for every note ` ` ` `for` `j ` `in` `range` `(k[i]): ` ` ` `temp ` `+` `=` `m[i][j] ` `*` `5` ` ` ` ` `# If value in temp is minimum ` ` ` `if` `temp < minn: ` ` ` `minn ` `=` `temp ` ` ` ` ` `print` `(minn) ` ` ` `# Driver Code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `# number of cashiers ` ` ` `n ` `=` `5` ` ` ` ` `# number of customers with ` ` ` `# each cashier ` ` ` `k ` `=` `[` `10` `, ` `10` `, ` `10` `, ` `10` `, ` `10` `] ` ` ` ` ` `# number of notes with each customer ` ` ` `m ` `=` `[[` `6` `, ` `7` `, ` `8` `, ` `6` `, ` `8` `, ` `5` `, ` `9` `, ` `8` `, ` `10` `, ` `5` `], ` ` ` `[` `9` `, ` `6` `, ` `9` `, ` `8` `, ` `7` `, ` `8` `, ` `8` `, ` `10` `, ` `8` `, ` `5` `], ` ` ` `[` `8` `, ` `7` `, ` `7` `, ` `8` `, ` `7` `, ` `5` `, ` `6` `, ` `8` `, ` `9` `, ` `5` `], ` ` ` `[` `6` `, ` `5` `, ` `10` `, ` `5` `, ` `5` `, ` `10` `, ` `7` `, ` `8` `, ` `5` `, ` `5` `], ` ` ` `[` `10` `, ` `9` `, ` `8` `, ` `7` `, ` `6` `, ` `9` `, ` `7` `, ` `9` `, ` `6` `, ` `5` `]] ` ` ` ` ` `# Calling function ` ` ` `minTimeToExchange(k, m, n) ` ` ` `# This code is contributed by ` `# sanjeev2552 ` |

*chevron_right*

*filter_none*

## C#

`// C# code to find minimum ` `// time to exchange notes ` `using` `System; ` ` ` `public` `class` `GFG { ` ` ` ` ` `// Function to calculate minimum ` ` ` `// time to exchange note ` ` ` `static` `void` `minTimeToExchange(` `int` `[]k, ` ` ` `int` `[,]m, ` `int` `n) ` ` ` `{ ` ` ` ` ` `int` `min = ` `int` `.MaxValue; ` ` ` ` ` `// Checking for every cashier ` ` ` `for` `(` `int` `i = 0; i < n; i++) ` ` ` `{ ` ` ` `// Time for changing the notes ` ` ` `int` `temp = k[i] * 15; ` ` ` ` ` `// Calculating scanning time ` ` ` `// for every note ` ` ` `for` `(` `int` `j = 0; j < k[i]; j++) ` ` ` `{ ` ` ` `temp += m[i,j] * 5; ` ` ` `} ` ` ` ` ` `// If value in temp is minimum ` ` ` `if` `(temp < min) ` ` ` `min = temp; ` ` ` `} ` ` ` ` ` `Console.WriteLine(min); ` ` ` `} ` ` ` ` ` `// Driver function ` ` ` `static` `public` `void` `Main (){ ` ` ` `// number of cashiers ` ` ` `int` `n = 5; ` ` ` ` ` `// number of customers with ` ` ` `// each cashier ` ` ` `int` `[]k = {10, 10, 10, 10, 10}; ` ` ` ` ` `// number of notes with each customer ` ` ` `int` `[,]m = {{6, 7, 8, 6, 8, 5, 9, 8, 10, 5}, ` ` ` `{9, 6, 9, 8, 7, 8, 8, 10, 8, 5}, ` ` ` `{8, 7, 7, 8, 7, 5, 6, 8, 9, 5}, ` ` ` `{6, 5, 10, 5, 5, 10, 7, 8, 5, 5}, ` ` ` `{10, 9, 8, 7, 6, 9, 7, 9, 6, 5}}; ` ` ` ` ` `// Calling function ` ` ` `minTimeToExchange(k, m, n); ` ` ` `} ` `} ` ` ` `// This code is contributed by vt_m. ` |

*chevron_right*

*filter_none*

## PHP

`<?php ` `// PHP code to find minimum ` `// time to exchange notes ` ` ` `// Function to calculate minimum ` `// time to exchange note ` `function` `minTimeToExchange(` `$k` `, ` `$m` `, ` ` ` `$n` `) ` `{ ` ` ` `$min` `= PHP_INT_MAX; ` ` ` ` ` `// Checking for every cashier ` ` ` `for` `( ` `$i` `= 0; ` `$i` `< ` `$n` `; ` `$i` `++) ` ` ` `{ ` ` ` ` ` `// Time for changing the notes ` ` ` `$temp` `= ` `$k` `[` `$i` `] * 15; ` ` ` ` ` `// Calculating scanning time ` ` ` `// for every note ` ` ` `for` `(` `$j` `= 0; ` `$j` `< ` `$k` `[` `$i` `]; ` `$j` `++) ` ` ` `{ ` ` ` `$temp` `+= ` `$m` `[` `$i` `][` `$j` `] * 5; ` ` ` `} ` ` ` ` ` `// If value in temp is minimum ` ` ` `if` `(` `$temp` `< ` `$min` `) ` ` ` `$min` `= ` `$temp` `; ` ` ` `} ` ` ` ` ` `echo` `$min` `; ` `} ` ` ` ` ` `// Driver Code ` ` ` `// number of cashiers ` ` ` `$n` `= 5; ` ` ` ` ` `// number of customers with ` ` ` `// each cashier ` ` ` `$k` `= ` `array` `(10, 10, 10, 10, 10); ` ` ` ` ` `// number of notes with ` ` ` `// each customer ` ` ` `$m` `= ` `array` `(` `array` `(6, 7, 8, 6, 8, 5, 9, 8, 10, 5), ` ` ` `array` `(9, 6, 9, 8, 7, 8, 8, 10, 8, 5), ` ` ` `array` `(8, 7, 7, 8, 7, 5, 6, 8, 9, 5), ` ` ` `array` `(6, 5, 10, 5, 5, 10, 7, 8, 5, 5), ` ` ` `array` `(10, 9, 8, 7, 6, 9, 7, 9, 6, 5)); ` ` ` ` ` `// Calling function ` ` ` `minTimeToExchange(` `$k` `, ` `$m` `, ` `$n` `); ` ` ` `// This code is contributed by anuj_67. ` `?> ` |

*chevron_right*

*filter_none*

Output:

480

## Recommended Posts:

- Find the time which is palindromic and comes after the given time
- Count of strings that become equal to one of the two strings after one removal
- Length of the longest subsegment which is UpDown after inserting atmost one integer
- Check if cells numbered 1 to K in a grid can be connected after removal of atmost one blocked cell
- Minimize the maximum minimum difference after one removal from array
- Find an integer X which is divisor of all except exactly one element in an array
- Find the numbers of strings that can be formed after processing Q queries
- Find the number of rectangles of size 2*1 which can be placed inside a rectangle of size n*m
- Find the sums for which an array can be divided into sub-arrays of equal sum
- Pair of arrays with equal sum after removing exactly one element from each
- Sub-strings that start and end with one character and have at least one other
- Count of vessels completely filled after a given time
- Design a structure which supports insertion and first non-repeating element in O(1) time
- Find the minimum number possible by changing at most one digit
- Check if any square (with one colored cell) can be divided into two equal parts
- How can one become good at Data structures and Algorithms easily?
- Count the total number of squares that can be visited by Bishop in one move
- Check if the bracket sequence can be balanced with at most one change in the position of a bracket | Set 2
- Largest number N which can be reduced to 0 in K steps
- Count the numbers which can convert N to 1 using given operation

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.