DWITE '07 R1 #4 - Stacks of Blocks

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Problem type
DWITE Online Computer Programming Contest, October 2007, Problem 4

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 will contain at least 3 lines, one positive integer value per line. The first line will contain an integer H, the target height for the stack. 0H100

The second line will contain an integer S, number of blocks in a set. 0S10

The next S lines will contain integers, one per line; 0N10; representing the height of blocks in the set.

The output file will contain a single integer value, a minimum number of blocks out of the supplied set, required to build a stack of the given height. If it is impossible to build the desired stack, output 0.

Sample Input 1

Copy
5
3
1
2
3

Sample Output 1

Copy
2

Sample Input 2

Copy
10
3
1
5
7

Sample Output 2

Copy
0

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments

There are no comments at the moment.