DWITE '07 R1 #4 - Stacks of Blocks

View as PDF

Submit solution

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
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. 0 \le H \le 100

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

The next S lines will contain integers, one per line; 0 \le N \le 10; 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


Sample Output 1


Sample Input 2


Sample Output 2


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.