6698.Ferris Wheel

Time Limit: 1s Memory Limit: 512MB

There are $n$ 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 $x$ . You know the weight of every child.

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

Input Format(From the terminal/stdin)

The first input line contains two integers $n$ and $x$ : the number of children and the maximum allowed weight.

The next line contains $n$ integers $p_1,p_2,\ldots,p_n$ : the weight of each child.

  • $1 \le n \le 2 \cdot 10^5$
  • $1 \le x \le 10^9$
  • $1 \le p_i \le x$

Output Format(To the terminal/stdout)

Print one integer: the minimum number of gondolas.

Sample Input

Copy
4 10
7 2 3 9
 ·  \n
 · · · \n

Sample Output

Copy
3
 \n
Source: CSES, Sorting and Searching, 1090

Submit

请先 登录

© 2025 FAQs