10411 - 麦香牛块

农夫布朗的奶牛们正在进行斗争,因为它们听说麦当劳正在考虑引进一种新产品:麦香牛块。奶牛们正在想尽一切办法让这种可怕的设想泡汤。奶牛们进行斗争的策 略之一是“劣质的包装”。“看,”,奶牛们说,“如果你用只有一次能装3块、6块或10块的三种包装盒装麦香牛块,你就不可能满足想要一次只想买1、2、 4、5、7、8、11、14或17块麦香牛块的顾客了。劣质的包装意味着劣质的产品。” 你的任务是帮助这些奶牛。给出包装盒的种类数N(1<=N<=10)和N个代表不同种类包装盒容纳麦香牛块个数的正整数(1<= i<=256),输出顾客不能用上述包装盒(每种盒子数量无限)买到麦香牛块的最大块数。如果在限定范围内所有购买方案都能得到满足,则输出0。 范围限制是所有不超过2,000,000,000的正整数。

输入

第1行: 包装盒的种类数N 第2行到N+1行: 每个种类包装盒容纳麦香牛块的个数

输出

输出文件只有一行数字:顾客不能用包装盒买到麦香牛块的最大块数或0(如果在限定范围内所有购买方案都能得到满足)。

样例

输入

3
3
6
10

输出

17

提示

Beef McNuggets Hubert Chen Farmer Brown's cows are up in arms, having heard that McDonalds is considering the introduction of a new product: Beef McNuggets. The cows are trying to find any possible way to put such a product in a negative light.

One strategy the cows are pursuing is that of inferior packaging'. Look,'' say the cows, `if you have Beef McNuggets in boxes of 3, 6, and 10, you can not satisfy a customer who wants 1, 2, 4, 5, 7, 8, 11, 14, or 17 McNuggets. Bad packaging: bad product.''

Help the cows. Given N (the number of packaging options, 1 <= N <= 10), and a set of N positive integers (1 <= i <= 256) that represent the number of nuggets in the various packages, output the largest number of nuggets that can not be purchased by buying nuggets in the given sizes. Print 0 if all possible purchases can be made or if there is no bound to the largest number.

The largest impossible number (if it exists) will be no larger than 2,000,000,000.

PROGRAM NAME: nuggets INPUT FORMAT Line 1: N, the number of packaging options Line 2..N+1: The number of nuggets in one kind of box

SAMPLE INPUT (file nuggets.in) 3 3 6 10

OUTPUT FORMAT The output file should contain a single line containing a single integer that represents the largest number of nuggets that can not be represented or 0 if all possible purchases can be made or if there is no bound to the largest number. SAMPLE OUTPUT (file nuggets.out) 17

时间限制 1 秒
内存限制 128 MB
讨论 统计
上一题 下一题