Two Parcels per Courier
Dispatch at QuickVan Logistics sends out one van per delivery run. A van can carry at most two
parcels on a run, and the combined weight of the parcels it carries must not exceed the van's
weight limit W kilograms. Every parcel weighs at most W kilograms by itself, so a parcel can
always be sent alone if it has no suitable partner.
Given the weights of n parcels waiting at the depot, find the minimum number of runs needed to
deliver all of them.
Input
The first line contains two integers n and W (1 ≤ n ≤ 2·10^5, 1 ≤ W ≤ 10^9).
The second line contains n integers w_1, w_2, ..., w_n (1 ≤ w_i ≤ W) — the weight of each parcel
in kilograms.
Output
Print a single integer: the minimum number of runs required to deliver all parcels.
Notes
In the first example, the 5 kg parcel has no partner light enough to share a run with it (even the lightest 1 kg parcel would push the pair to 6 kg), so it travels alone. The remaining four parcels pair up as (1, 3) and (2, 2), giving 3 runs in total.
In the second example, pairing the lightest parcel with the heaviest one first is essential: sending (1, 4) and (2, 3) finishes everyone in 2 runs. Repeatedly pairing the two heaviest parcels instead — (4, 3) together, then 2 alone, then 1 alone — would take 3 runs, which is not optimal.