This page is still under construction.

Parts of this page are still being built. What you see may change.

Bin Packing

Interview

Time limit1sMemory limit128 MB

Summary
Pack items into identical bins holding at most two items each so that the number of bins is minimized.
Level

Medium5 of 10

Topics
Greedy, Two pointers, Sorting, Array
Solved
No attempts yet

Problem

You must pack nn one-dimensional items into identical bins. Every bin has the same length ll, and each item ii has length li≤ll_i \le l.

Find the minimum number of bins qq such that all of the following hold:

  • Each bin contains at most 2 items.
  • Every item is packed into exactly one bin.
  • The total length of the items in any single bin does not exceed ll.

Given the integers nn, ll, and l1,…,lnl_1, \dots, l_n, compute the minimum number of bins qq.

Input

The first line contains the number of items nn (1≤n≤1051 \le n \le 10^5).

The second line contains the bin length ll (1≤l≤100001 \le l \le 10000).

Each of the next nn lines contains one item length lil_i (1≤li≤l1 \le l_i \le l).

Output

Print a single line containing the minimum number of bins needed to pack all items.

The figure below shows one optimal packing.

Examples1

  1. Example 1

    Input
    10
    80
    70
    15
    30
    35
    10
    80
    20
    35
    10
    30
    
    Expected output
    6