CBOJ Winter Contest Problem 3 - Stacking Spacers
Bob went to the hardware shop, and bought \(N\) spacers of height \(h_i\). He needs to use the spacers to fix a gap of size \(M\) in his roof. What is the least number of spacers he needs to perfectly fix the gap?
Input Specification
The first line of input will contain two integers, \(N\) \((1 \le N \le 100)\) and \(M\) \((1 \le M \le 10000)\).
The next line will contain \(N\) integers \(h_i\) ranging from \(1\) to \(10000\) inclusive, indicating the height of each spacer Bob bought. Note that each spacer can only be used once (hence, Bob can use at most \(N\) spacers).
Output Specification
Output one integer, the minimum number of spacers Bob needs to fix the gap in his roof. If this is not possible, output -1
.
Subtasks
Subtask 1 [30%]
\(1 \le N \le 25\)
Subtask 2 [70%]
No additional constraints.
Sample Input:
7 15
12 2 8 6 2 7 1
Sample Output:
2
Sample Explanation:
Bob can choose spacers of height 7 and 8.
7 + 8 = 15
Comments