PDP-27 (2015) - Camp juniors - 2 (elev2)

View as PDF

Submit solution

Points: 30 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem types
Allowed languages
C, C++, Java, Pascal, Python

ELEV2

An elevator can accommodate at most two people with a maximum weight of B kilograms (combined weight). On the ground floor, there are N people waiting to use the elevator to go to the top floor. Fortunately, we know the weights W_i 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 N and B, separated by a single space: the total number of people and the maximum weight allowed. The second line of input will contain N natural numbers W_i, 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

1 \le N \le 1.000.000
1 \le B \le 1.000.000
1 \le W_i \le B
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 7 trips, carrying, for example, one or two people in order, with total weights of 93, 114, 45 + 92, 114, 70 + 67, 99, 90 + 57. It is not possible to transport these people with fewer than 7 trips.


Comments

There are no comments at the moment.