#C3257. Minimum Chemicals to Target

    ID: 46664 Type: Default 1000ms 256MiB

Minimum Chemicals to Target

Minimum Chemicals to Target

Given a set of n chemicals, each with a specified effect value, determine the minimum number of chemicals required such that their combined effect exactly equals a target value t. Formally, given a set \( S = \{a_1, a_2, \ldots, a_n\} \) and a target effect \( t \), find the smallest subset \( T \subseteq S \) such that \( \sum_{x \in T} x = t \). If there is no such subset, output \(-1\).

inputFormat

The input consists of two lines. The first line contains two integers (n) and (t) separated by a space. The second line contains (n) space-separated integers representing the effect values of the chemicals. When (n = 0), the second line will be empty.

outputFormat

Output a single integer representing the minimum number of chemicals required to achieve the target effect (t). If it is not possible, output (-1).## sample

3 7
2 3 5
2