ELEV2
An elevator can accommodate at most two people with a maximum weight of kilograms (combined weight). On the ground floor, there are people waiting to use the elevator to go to the top floor. Fortunately, we know the weights of all of them.
Write a program that reads this data and finds the minimum number of trips the elevator must make to transport all people. Consider that the elevator starts from the ground floor and that a trip includes going up and then down (with an empty elevator).
Input
The first line of input will contain two natural numbers and , separated by a single space: the total number of people and the maximum weight allowed. The second line of input will contain natural numbers , separated in pairs by a single space: the weights of the people waiting.
Output
The output should consist of exactly one line containing exactly one natural number, the minimum number of trips the elevator must make.
Constraints
Time Limit: 1 sec.
Maximum Available Memory: 64 MB
Example of Input - Output
STDIN (elev2.in)
10 150
114 57 67 70 93 99 92 114 45 90
STDOUT (elev2.out)
7
Explanation of the Example: The elevator can make trips, carrying, for example, one or two people in order, with total weights of , , , , , , . It is not possible to transport these people with fewer than trips.
Comments