P25411 [AtCoder] Storage
提高-
题目描述

Problem Description

There are $ N $ rods, and the length of the $ i(1≦i≦N) $th rod is $ L_i $.

These rods will be stored in cases of length $ C $.

A case can store either $ 1 $ or $ 2 $ rods, but the conditions for storing rods are:

  • For storing $ 1 $ rod, if the length of the rod is $ a $, then $ a≦C $.
  • For storing $ 2 $ rods, if the lengths of the rods are $ a,b $, then $ a+b+1≦C $.

Answer the minimum number of cases needed to store all the rods.

Input Format

The input is given from the standard input in the following format:

$ N $ $ C $ $ L_1 $ $ : $ $ L_N $

Output Format

When the minimum number of cases needed is $ x $, output $ x $.

Sample Input and Output

Sample Input #1

4 10
2
8
4
5

Sample Output #1

3

Sample Input #2

3 10
1
1
1

Sample Output #2

2

Sample Input #3

9 30
22
5
2
18
6
21
29
11
18

Sample Output #3

5

Notes/Hints

Constraints

  • $ 1≦N≦100000 $
  • $ 1≦C≦10^9 $
  • $ 1≦L_i≦C $
  • The input consists of integers.

Sample Explanation 1

The $ 3 $rd rod and $ 4 $th rod can be stored in the same case, and the $ 1 $st and $ 2 $nd rods can be stored in separate cases, which requires $ 3 $ cases in total.

Sample Explanation 2

Note that a case can only store up to $ 2 $ rods.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 10 2 8 4 5
样例输出
3