#P2725. [USACO3.1] 邮票 Stamps
[USACO3.1] 邮票 Stamps
Description
Given a set of stamp denominations and an upper bound — meaning you may affix at most stamps to an envelope — find the largest positive integer such that every value from to can be represented using no more than stamps.
Input Format
The first line contains two integers, the stamp limit and the number of denominations .
Starting from the second line, except for the last line, each line contains integers . The last line contains at most integers. In total there are integers; the -th integer is the value of the -th type of stamp.
Output Format
Output one line with a single integer . If does not exist, output .
5 2
1 3
13
Hint
Sample Input/Output 1 Explanation
There are denominations and ; you may use at most stamps. It is easy to form values through (just use the -value stamps). The following values are also easy:
- .
- .
- .
- .
- .
- .
- .
- .
However, using stamps of values or , it is impossible to form . Therefore, the answer is .
Constraints
- For of the testdata, , , .
Note
- The statement is translated from NOCOW.
Translated by ChatGPT 5
京公网安备 11011102002149号