Battery Pack Merging
Your device needs at least T total charge before it can turn on.
You have n battery packs, and the i-th pack provides ci 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 T.
What is the minimum number of battery packs needed to reach at least T total charge? If even
using every battery pack is not enough, output -1.
Input
The first line contains two integers n and T.
The second line contains n integers c1,c2,…,cn, where ci is the charge of the i-th battery pack.
Output
Output a single integer: the minimum number of battery packs needed to reach at least T total
charge, or -1 if it is impossible.
Constraints
- 1≤n≤2×105
- 1≤T≤1014
- 1≤ci≤109
Example 1
5 12
3 8 4 5 2
2
Explanation
Using the packs with charge 8 and 5 gives a total of 13, so two packs are enough.
Example 2
4 20
6 4 5 3
-1
Explanation
All four packs together only give 18 total charge.
Example 3
2 10
9 9
2
Explanation
One pack is not enough, but both packs together give 18 total charge.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.