Battery Pack Merging
View as PDFYour device needs at least total charge before it can turn on.
You have battery packs, and the
-th pack provides
units of charge. Each pack can be
used at most once, and you may merge any collection of packs together. It is allowed for the total
charge to be more than
.
What is the minimum number of battery packs needed to reach at least total charge? If even
using every battery pack is not enough, output
-1.
Input
The first line contains two integers and
.
The second line contains integers
, where
is the charge of the
-th battery pack.
Output
Output a single integer: the minimum number of battery packs needed to reach at least total
charge, or
-1 if it is impossible.
Constraints
Example 1
Input
5 12
3 8 4 5 2
Output
2
Explanation
Using the packs with charge and
gives a total of
, so two packs are enough.
Example 2
Input
4 20
6 4 5 3
Output
-1
Explanation
All four packs together only give total charge.
Example 3
Input
2 10
9 9
Output
2
Explanation
One pack is not enough, but both packs together give total charge.
Comments