Exact Change
InterviewTime limit1sMemory limit1024 MB
Given package values in cents, find the smallest positive amount that no subset of the packages can sum to exactly.
Problem
Whenever the UCF Programming Team travels to World Finals, Glenn likes having the exact amount of money needed for any purchase, so that he does not have to count or receive change. Most countries do not have many coin denominations, so Glenn makes "packages" of money, each with a fixed amount in cents. Glenn wants to know the smallest amount in cents that he cannot pay exactly using some combination of his packages.
Given a list of positive integers, find the smallest integer that cannot be written as the sum of some subset of the integers in the list.
Input
The first line contains a single integer (), the number of package sets to evaluate. Each of the sets follows. The first line of each set contains a single integer (), the number of different packages. The next line contains exactly positive integers separated by single spaces, the value of each package in cents. The sum of these integers does not exceed . Package values need not be distinct, so several packages may have the same value.
Output
For each set, first print "Set #i: " where is the set number starting at 1. Then print a single positive integer, the smallest value that cannot be represented as a sum of a subset of the packages. A package can be used at most once, but if packages share the same value, up to of them can be used in one subset. Leave a blank line after the output for each test case.