Clothes on a rope

A rope is L units long and you have N clothes; cloth i is A[i] units wide. Clothes hang side by side, and each cloth needs a clip at both ends, but two neighbouring clothes share the clip between them, so K clothes need K + 1 clips. Every clip also takes 1 unit of rope. What is the largest number of clothes you can hang?

Reported in: Infosys (SP / DSE · 29 Nov 2026) (memory-based)

Input

First line: N and L. Second line: N widths.

Output

The largest number of clothes that fit.

Constraints

1 ≤ N ≤ 10^5; 1 ≤ L, A[i] ≤ 10^9.

Example 1

Input:
5 10
2 3 5 4 6

Output:
2

Example 2

Input:
4 12
4 3 2 1

Output:
3

Example 3

Input:
3 4
3 5 6

Output:
0

Hint: K clothes use (sum of their widths) + K + 1 units of rope. To fit as many as possible, take the narrowest clothes first and stop when the next one does not fit.

All coding practice