Rescue Boats
View as PDFDuring an evacuation, people must cross a river using rescue boats.
Each boat can carry at most two people, and the total weight of the people in a boat must be at
most .
Given the weight of every person, determine the minimum number of boats needed to carry everyone.
Input
The first line contains two integers and
, the number of people and the maximum total
weight a boat can carry.
The second line contains integers
, where
is the weight of the
-th person.
It is guaranteed that every person can fit in a boat alone.
Output
Print a single integer: the minimum number of boats needed.
Constraints
Example 1
Input
4 3
3 2 2 1
Output
3
Explanation
One optimal arrangement is ,
, and
.
Example 2
Input
6 10
1 2 3 7 8 9
Output
3
Explanation
One optimal arrangement is ,
, and
.
Example 3
Input
5 5
5 5 5 5 5
Output
5
Comments