There are two cash lockers, one has X number of coins and the other has Y number of coins, you can withdraw money at max two times, when you withdraw from a locker you will get the total money of the locker and the locker will be refilled with Z – 1 coins if it had Z coins initially. The task is to find the maximum coins you can get.
Input: X = 6, Y = 3
Take from locker X i.e. 6
Now, X = 5 and Y = 3
Take again from locker X i.e. 5.
Input: X = 4, Y = 4
Approach: In order to maximize the number of coins, take from the locker which has the maximum value then update the locker and again take from the locker with the maximum value.
Below is the implementation of the above approach:
- Select numbers in such way to maximize the amount of money
- Minimize Cash Flow among a given set of friends who have borrowed money from each other
- Total money to be paid after traveling the given number of hours
- Check if it is possible to move from (0, 0) to (x, y) in N steps
- Largest number N which can be reduced to 0 in K steps
- Find the number of stair steps
- Count minimum steps to get the given desired array
- Probability of reaching a point with 2 or 3 steps at a time
- Number of steps to convert to prime factors
- Minimum steps to color the tree with given colors
- Number of steps required to reach point (x,y) from (0,0) using zig-zag way
- Generate array with minimum sum which can be deleted in P steps
- Print steps to make a number in form of 2^X - 1
- Number of odd and even results for every value of x in range [min, max] after performing N steps
- Find the minimum number of steps to reach M from N
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.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.