#K10731. Minimum Plank Count

    ID: 23312 Type: Default 1000ms 256MiB

Minimum Plank Count

Minimum Plank Count

You are given n wooden planks with various lengths and a target length L. Your goal is to determine the minimum number of planks required to achieve exactly the length L. It is guaranteed that it is always possible to achieve the target length by using either one or two planks.

The rules are as follows:

  • If there exists a plank with length equal to L, then the answer is 1.
  • Otherwise, find two planks such that their sum is exactly L and the answer is 2.

Note: Under the given constraints, you do not have to consider using more than two planks.

The formula behind the solution can be represented as:

$$ answer = \begin{cases} 1 & \text{if } L \in \{a_1, a_2, \dots, a_n\} \\ 2 & \text{otherwise (assuming } \exists\, i,j\text{ such that } a_i+a_j = L) \end{cases} $$

inputFormat

The first line contains two integers n and L, where n is the number of planks and L is the target length. The second line contains n space-separated integers representing the lengths of the available planks.

outputFormat

Output a single integer representing the minimum number of planks required to achieve the target length L.## sample

5 9
5 6 4 7 10
2