#K93672. Minimum Boat Trips

    ID: 38472 Type: Default 1000ms 256MiB

Minimum Boat Trips

Minimum Boat Trips

You are given a list of hikers, each represented by their weight, and a boat that can carry at most two hikers at a time. The boat has a weight capacity limit. Your task is to determine the minimum number of boat trips required to transport all hikers across the river.

When two hikers share a boat, their combined weight must satisfy the inequality \(w_i + w_j \leq limit\). Otherwise, a hiker must cross alone.

inputFormat

The input is given via standard input (stdin). The first line contains two integers n and limit, where n is the number of hikers and limit is the maximum weight capacity of the boat. The second line contains n space-separated integers representing the weights of the hikers.

outputFormat

Output a single integer on standard output (stdout), which is the minimum number of boat trips required to get all the hikers across the river.## sample

4 100
70 50 80 50
3

</p>