
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find the minimum time after which one can exchange notes in Python
Suppose there are n number of cashiers exchanging the money, at the moment, the i-th cashier had ki number of people in front of him/her. Now, the j-th person in the line to i-th cashier had m[i,j] notes. We have to find how early can one exchange his/her notes. We have to keep in mind that the cashier spent 5 seconds to scan a single note.After completing scanning of every note for the customer, he/she took 15 seconds to exchange the notes.
So, if the input is like Input : n = 6, k = [12, 12, 12, 12, 12, 12]
7 | 8 | 9 | 7 | 9 | 6 | 10 | 9 | 9 | 6 | 7 | 8 |
10 | 7 | 10 | 9 | 8 | 9 | 9 | 9 | 9 | 6 | 5 | 6 |
9 | 8 | 8 | 9 | 8 | 6 | 7 | 9 | 10 | 6 | 6 | 7 |
7 | 6 | 9 | 6 | 6 | 9 | 8 | 9 | 6 | 6 | 8 | 9 |
9 | 8 | 7 | 6 | 5 | 10 | 8 | 10 | 7 | 6 | 6 | 8 |
8 | 7 | 6 | 5 | 7 | 9 | 7 | 9 | 6 | 5 | 5 | 7 |
then the output will be 585, as the cashier needs 5 secs for scanning every note of each customer, so add 5*m[I,j]. Now each cashier takes 15 seconds for every customer, so add 15*k[] to the answer. The minimum time taken after computing the time taken by each cashier will be the answer. So cashier m[5] takes the minimum time 585.
To solve this, we will follow these steps −
n := size of k
minimum := 99999
for i in range 0 to n, do
temp := k[i] * 15
for j in range 0 to k[i], do
temp := temp + m[i, j] * 5
if temp < minimum, then
minimum := temp
return minimum
Example
Let us see the following implementation to get better understanding −
def minTimeToExchange(k, m): n = len(k) minimum = 99999 for i in range(n): temp = k[i] * 15 for j in range(k[i]): temp += m[i][j] * 5 if temp < minimum: minimum = temp return minimum k = [12, 12, 12, 12, 12, 12] m = [ [7,8,9,7,9,6,10,9,9,6,7,8], [10,7,10,9,8,9,9,9,9,6,5,6], [9,8,8,9,8,6,7,9,10,6,6,7], [7,6,9,6,6,9,8,9,6,6,8,9], [9,8,7,6,5,10,8,10,7,6,6,8], [8,7,6,5,7,9,7,9,6,5,5,7]] print(minTimeToExchange(k, m))
Input
[12, 12, 12, 12, 12, 12], [[7,8,9,7,9,6,10,9,9,6,7,8], [10,7,10,9,8,9,9,9,9,6,5,6], [9,8,8,9,8,6,7,9,10,6,6,7], [7,6,9,6,6,9,8,9,6,6,8,9], [9,8,7,6,5,10,8,10,7,6,6,8], [8,7,6,5,7,9,7,9,6,5,5,7]]
Output
585
- Related Articles
- Find the time which is palindromic and comes after the given time in Python
- Python Get the real time currency exchange rate?
- Find the minimum number of rectangles left after inserting one into another in C++
- Program to find number of sublists containing maximum and minimum after deleting only one element in Python
- Program to find minimum number colors remain after merging in Python
- Program to find minimum amplitude after deleting KLength sublist in Python
- Program to find minimum amplitude after deleting K elements in Python
- How can we create a MySQL one-time event that executes after some specified time interval?
- Program to find minimum time to complete all tasks in python
- Program to find minimum time to finish all jobs in Python
- Program to find minimum possible maximum value after k operations in python
- Find minimum number of currency notes and values that sum to given amount in C++
- Find minimum time to finish all jobs with given constraints in Python
- Program to find minimum length of string after deleting similar ends in Python
- Program to find expected growth of virus after time t in Python
