Question
Minimum Rescue Boats

You are given an array people, where people[i] represents the weight of the i-th person. You also have an unlimited number of boats, each capable of carrying at most two people as long as their combined weight does not exceed a given limit.

Your task is to determine the minimum number of boats required to transport all the people.

Input
The first line contains an integer n representing the size of the array people.
The next line contains n integers representing the weights of the people.
The last line contains an integer representing the weight limit of each boat.
Output
Print the minimum number of boats to carry every given person.
Example
Sample input:
2
1 2
3
Sample Output:
1
Explanation
Both people (weights 1 and 2) can share a single boat because their total weight equals the limit (3).

Online