public:
int numRescueBoats(vector<int>& people, int limit) {
sort(people.begin(), people.end());
int res = 0, left = 0, right = people.size() - 1;
while(left <= right) {
if(people[left] + people[right] <= limit){
res ++;
left++;
right --;
}
else {
res ++;
right --;
}
}
return res;
}
};