#K50877. Minimum Boat Runs
Minimum Boat Runs
Minimum Boat Runs
Given a list of people with their weights and a boat with a limited capacity \(C\), determine the minimum number of boat trips required to rescue everyone. In each trip, the boat can carry at most two people, and the sum of their weights must not exceed \(C\). Your goal is to pair people optimally so that the total number of trips is minimized.
Note: The problem requires you to use an efficient greedy strategy, often implemented using sorting and the two-pointer technique.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two integers \(N\) and \(C\), where \(N\) is the number of people and \(C\) is the boat's capacity.
- The second line contains \(N\) space-separated integers representing the weights of the people.
outputFormat
Print a single integer to stdout which represents the minimum number of boat trips required to rescue all people.
## sample4 100
50 50 70 80
3