Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Automatic coin exchange machine ( CoinChange ) Automated coin exchange machines are everywhere. Especially in systems that require coins to pay for the value of
Automatic coin exchange machine CoinChange
Automated coin exchange machines are everywhere. Especially in systems that require coins to pay for the value of things or services, users must bring the banknotes they want to exchange for coins into the automatic coin exchange machine. And the automatic coin exchange machine returns the user with different types of coins, each of which has a different value per coin. The total value of all coins is equal to the value of all banknotes imported by the user. But the number of coins of each type may not be the same. In addition, so that the automatic coin exchange machine can provide coin exchange services to customers for a long time. The automatic coin exchange machine will calculate the coins returned to the user. The important condition is that the total number of coins must be as small as possible.
Have students write a program to receive input data as follows.
Total value of banknotes that the user wishes to exchange for coins A baht
Number of different types of coins. Available in automatic coin exchangers N type
Value of each type of coin Ci baht, i N
To calculate and display the total number of coins that the automatic coin exchange machine will return to the user.
Example : Total value of banknotes that the user wishes to exchange for baht coins. In an automatic coin exchange machine, there are types of coins, each with a value of baht, baht, and baht.
The automatic coin exchange machine will return coins to the user with a total value of baht as follows x x
Example : Total value of banknotes that the user wishes to exchange for baht coins. In an automatic coin exchange machine, there are types of coins, each with a value of baht, baht, and baht.
The automatic coin exchange machine will return coins to the user, total value baht, as follows x
input data
The input data has N lines as follows.
Line one Consisting of one integer, specifying the value A let A represent the total value of banknotes that the user wishes to exchange for coins.
The second line consists of one integer specifying the value N where N represents the number of different types of coins. which is available in automatic coin exchange machines
Lines through N each contain one integer Ci i N representing the value of each type of coin. which is available in automatic coin exchange machines
note
Specify that every input always has the correct format, bounds, and set of possible values. Students do not need to validate their input.
Export data
The output data has one line. Displays the result as a single integer. Specifies the total number of coins that the vending machine will return to the user.
Example
input data
Export data
Example
input data
Export data
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started