Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-qayiqlar

Crossing the river

Medium 1000 ms 128 MB 56%
Share

$n$ people have to cross a river; the weight of the $i$-th person is $w_{i}$. Each boat takes at most two people, and their total weight must not exceed $C$. Find the smallest number of boats needed to get everyone across.

Diagram of placing people into two-seat boats

Input

The first line contains two positive integers: $n$ and $C$. The second line contains $n$ space-separated positive integers $w_{i}$.

Output

One integer — the smallest number of boats.

Note

$1 \le n \le 10^{5}$
$1 \le w_{i} \le C \le 10^{9}$

Examples

Input #1
4 100
60 40 70 30
Output #1
2
Input #2
3 50
50 50 50
Output #2
3

Sign in to submit a solution

Signing up is free and takes a minute.