Some kids play with blocks and build things by stacking different blocks on top of each other. Given a set of blocks and a target height, we want to find out if it’s possible to construct a stack with an exact specified height.
The input file DATA4.txt will contain at least 3 lines, with one positive integer value per line. The first line will contain an integer H, the target height for the stack. 0 < H < 100.
The second line will contain an integer S, the number of blocks in the set. 0 < S < 10.
The next S lines will contain integers, one per line, 0 < N < 10, representing the height of the blocks in the set.
The output file OUT4.txt will contain a single integer value, which is the minimum number of blocks from the supplied set that is required to build a stack of the given height. If it is impossible to build the desired stack, output 0.
5
3
1
2
3
2
10
3
1
5
7
0