#P2842. 纸币问题 1

纸币问题 1

Problem Description

A country has nn types of banknotes. Each type has denomination aia_i, and there are infinitely many banknotes of each type. Now you need to make up an amount of ww. What is the minimum number of banknotes needed to make up this amount? (It is guaranteed that the amount can be made up.)

Input Format

The first line contains two integers n,wn, w, representing the number of banknote types and the target amount to make up.
The second line contains nn integers separated by spaces: a1,a2,a3,ana_1, a_2, a_3, \dots a_n, representing the denominations of these nn types of banknotes in order.

Output Format

One line with one integer, representing the minimum number of banknotes used.

6 15
1 5 10 20 50 100
2
3 15
1 5 11
3

Hint

For 40%40\% of the testdata, n10n \le 10 and w100w \le 100.
For 100%100\% of the testdata, 1n1031 \le n \le 10^3 and 1ai,w1041 \le a_i, w \le 10^4.

Constraints

Translated by ChatGPT 5