#P2842. Minimum Number of Bills

    ID: 16101 Type: Default 1000ms 256MiB

Minimum Number of Bills

Minimum Number of Bills

There are \(n\) types of bills in a country. Each bill has a denomination \(a_i\) and there is an infinite supply of each type. Given an integer \(w\) representing the target amount, determine the minimum number of bills needed to form exactly \(w\). If it is impossible to form \(w\) exactly, output -1.

Note: If it is not possible to form the amount, print -1.

Constraints:

  • 1 \(\leq n \leq\) 100
  • 1 \(\leq a_i, w \leq\) 104

inputFormat

The first line contains two integers \(n\) and \(w\) separated by a space.

The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\) which represent the denominations of the bills.

outputFormat

Output a single integer which is the minimum number of bills required to form the amount \(w\). If it is impossible to form \(w\), output -1.

sample

3 11
1 5 7
3