SHOP
InterviewTime limit2sMemory limit512 MB
Given an amount to return and a limited supply of each bill denomination, choose bills of the highest denominations so the total equals the amount.
- Level
Medium5 of 10
- Topics
- Greedy, Sorting, Implementation, Math
- Solved
- No attempts yet
Problem
Ahmad is a shopkeeper working in a market. When a customer pays him for shopping, he has to give back the change. Ahmad always wants to pay with the highest bills if possible. Write a program to help Ahmad.
Input
The first line contains , the number of test cases ().
Each test case has two lines. The first line contains the amount that Ahmad must return to the customer (). The second line contains . is the denomination of a bill and is the number of bills Ahmad has for that ().
Output
Print the bills Ahmad needs to return to the customer, sorted by denomination in descending order.