PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000033. Đu quay (Ferris Wheel)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đu quay (Ferris Wheel)
Ferris Wheel
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are children waiting for a Ferris wheel. A gondola can carry one or two children, and their combined weight cannot exceed . Child weighs . Every child must board exactly one gondola. Determine the minimum number of gondolas required.
Input
- The first line contains and : the number of children and the maximum combined weight in one gondola.
- The second line contains integers , the children's weights.
Output
Print a single integer: the minimum number of gondolas needed for all the children.
Subtasks
- Subtask 1 (20 points): ; ; for all .
- Subtask 2 (30 points): ; ; for all .
- Subtask 3 (50 points): ; ; for all .
Examples
Input
4 10
7 2 3 9
Output
3
Explanation
The weights are and . Pair weights and in one gondola; they sum to . The children weighing and cannot share because , so they use two additional gondolas. Thus gondolas suffice; do not.