Rescue Boats

View as PDF

Submit solution


Points: 100
Time limit: 2.0s
Memory limit: 977M

Problem type

During an evacuation, n 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 x.

Given the weight of every person, determine the minimum number of boats needed to carry everyone.

Input

The first line contains two integers n and x, the number of people and the maximum total weight a boat can carry.

The second line contains n integers w_1, w_2, \ldots, w_n, where w_i is the weight of the i-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

  • 1 \le n \le 2 \cdot 10^5
  • 1 \le w_i \le x \le 10^9

Example 1

Input
4 3
3 2 2 1
Output
3
Explanation

One optimal arrangement is [1, 2], [2], and [3].

Example 2

Input
6 10
1 2 3 7 8 9
Output
3
Explanation

One optimal arrangement is [1, 9], [2, 8], and [3, 7].

Example 3

Input
5 5
5 5 5 5 5
Output
5

Comments

There are no comments at the moment.