Thornhill Computer Club 2024 - April Contest - Problem 5
cups of flour. However, all the markings on his measurement devices have been erased, leaving him unable to measure precise amounts of flour. Luckily, knows the th measuring device can hold cups of flour when completely filled. Instead of buying new measuring devices, wants to know if he can measure exactly cups of flour using his measuring devices. Can you determine the minimum number of times needs to measure out flour only using his measuring devices before he has exactly cups? If it is impossible to do so, output -1
.
Input Specification
The first line will contain two integers and , the number of cups of flour and number of measuring devices.
The next line will contain integers , the number of cups of flour the th measuring device can hold.
Output Specification
Output a single integer, the minimum number of times -1
if it is impossible.
Sample Input 1
100 3
33 40 1
Sample Output 1
4
Explanation for Sample Output 1
33
cups of flour three times and 1
cup of flour one time.
Sample Input 2
12 4
1 2 3 4
Sample Output 2
3
Explanation for Sample Output 2
4
cups of flour three times.
Sample Input 3
203 3
16 33 54
Sample Output 3
-1
Explanation for Sample Output 3
It is impossible for 18
cups of flour using measurement devices of 16
, 33
, and 54
.
Comments