PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000033. Đu quay (Ferris Wheel)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

2 lộ trình

Đu quay (Ferris Wheel)

Ferris Wheel

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn children waiting for a Ferris wheel. A gondola can carry one or two children, and their combined weight cannot exceed xx. Child ii weighs pip_i. Every child must board exactly one gondola. Determine the minimum number of gondolas required.

Input

  • The first line contains nn and xx: the number of children and the maximum combined weight in one gondola.
  • The second line contains nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n, the children's weights.

Output

Print a single integer: the minimum number of gondolas needed for all the children.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; 1≤x≤1091\le x\le10^9; 1≤pi≤x1\le p_i\le x for all 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤x≤1091\le x\le10^9; 1≤pi≤x1\le p_i\le x for all 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤x≤1091\le x\le10^9; 1≤pi≤x1\le p_i\le x for all 1≤i≤n1\le i\le n.

Examples

Input

4 10
7 2 3 9

Output

3

Explanation

The weights are 7,2,3,97,2,3,9 and x=10x=10. Pair weights 77 and 33 in one gondola; they sum to 1010. The children weighing 22 and 99 cannot share because 2+9=11>102+9=11>10, so they use two additional gondolas. Thus 33 gondolas suffice; 22 do not.