Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Ferris Wheel

#1090
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

There are nn children who want to go to a Ferris wheel, and your task is to find a gondola for each child.

Each gondola may have one or two children in it, and in addition, the total weight in a gondola may not exceed xx. You know the weight of every child.

What is the minimum number of gondolas needed for the children?

Input

The first input line contains two integers nn and xx: the number of children and the maximum allowed weight.

The next line contains nn integers p1,p2,…,pnp_1,p_2,\ldots,p_n: the weight of each child.

Output

Print one integer: the minimum number of gondolas.

Constraints
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 1≤x≤1091 \le x \le 10^9
  • 1≤pi≤x1 \le p_i \le x
Sample Test Cases (1)
Example 1ID: sample-1
Input
4 10
7 2 3 9
Expected Output
3
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
4 10
7 2 3 9
Expected Output
3