The cashier who always grabs the biggest note
A bazaar stall in Istanbul has a cash drawer with unlimited notes and coins of several denominations. The cashier is in a hurry, so she follows a strict habit when giving change: she repeatedly hands over the largest denomination that does not exceed the amount still owed, until nothing more can be handed over. If the denominations cannot make the exact amount (for example there is no coin of 1), some money stays owed.
Task: the first line holds the change amount A (0 to 1000000). The second line holds the available denominations separated by spaces (1 to 12 distinct positive integers, in any order). Print one line with two integers separated by a space: the total number of notes and coins handed over, and the amount still owed after the cashier follows her habit (0 if the change was exact).
Sample test
Input
1289 1000 500 100 50 20 10 5 1
Expected output
11 0
Your answer is also checked against 5 hidden tests.
Need a hint?
Sort the denominations from large to small. For each one, how many fit into what is left?
Log in or create a free account to run your code, submit and earn points.
Run your code to see the output here. Ctrl + Enter also runs it.
