881. Boats to Save People
Note:
1 <= people.length <= 50000
1 <= people[i] <= limit <= 30000
class Solution {
public:
int numRescueBoats(vector<int>& people, int limit) {
if(people.empty()) return 0;
std::sort(people.begin(), people.end());
int i = 0;
int j = people.size() - 1;
int ans = 0;
while(i <= j){
ans++;
if(people[i] + people[j] <= limit)
i++;
j--;
}
return ans;
}
};