#P7396. Automatic Coin Exchange
Automatic Coin Exchange
Automatic Coin Exchange
The Mca city's metro company has introduced a new measure: passengers board the train by simply inserting coins instead of buying tickets. It is rumored that the objective is to reduce the time spent waiting in ticket queues. The metro operator has commissioned the ACM (Automated Checkout Machine) company to develop an Automatic exChange Machine (ACM) to meet this need. Your task is to write a program for the machine that converts a banknote into coins. The machine stores coins in various denominations and, when given a banknote of value \(A\), it must dispense coins that sum up to \(A\) while minimizing the total number of coins dispensed.
If an exact change cannot be made with the available coin denominations, the machine should output a message advising the passenger to seek manual service.
Input Format:
The input consists of three lines:
1. An integer \(A\) (\(0 \leq A \leq 10000\)), the value of the banknote to be exchanged.
2. An integer \(N\) (\(1 \leq N \leq 100\)), the number of available coin denominations.
3. \(N\) space-separated positive integers (each \(\leq A\)), representing the coin denominations available in unlimited quantity.
Output Format:
If an exact exchange is possible, output a single line containing the selected coin denominations separated by a space in descending order (i.e. sorted in non-increasing order) such that their sum is \(A\) and the total number of coins is minimized. If it is not possible to exchange \(A\) exactly, output the line "NO EXACT CHANGE".
inputFormat
Line 1: An integer \(A\), the value to exchange.
Line 2: An integer \(N\), the number of coin types.
Line 3: \(N\) space-separated integers representing the coin denominations available.
outputFormat
If the exchange is possible, output the coin denominations (in descending order) separated by spaces; otherwise, output "NO EXACT CHANGE".
sample
11
3
1 5 7
5 5 1