Problem
You are given a list people where people[i] is the weight of person i, and an unlimited number of boats. Each boat can carry at most two people at the same time, as long as their total weight is at most `limit`. Return the minimum number of boats needed to carry everyone.
Example 1
- Input
- people = [1, 2], limit = 3
- Output
- 1
- Why
- both fit in one boat
Example 2
- Input
- people = [3, 2, 2, 1], limit = 3
- Output
- 3
- Why
- (1, 2), (2), (3)
Example 3
- Input
- people = [3, 5, 3, 4], limit = 5
- Output
- 4
- Why
- nobody can share
Constraints
1 <= people.length <= 5 * 10^41 <= people[i] <= limit <= 3 * 10^4