#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
int numRescueBoats(vector<int>& people, int limit) {
sort(people.begin(), people.end());
int boats = 0;
int left = 0, right = people.size() - 1;
while (left <= right) {
if (people[left] + people[right] <= limit) {
left++;
}
right--;
boats++;
}
return boats;
}
};
int main() {
Solution solution;
// Example usage:
vector<int> people = {3, 2, 2, 1};
int limit = 3;
int result = solution.numRescueBoats(people, limit);
cout << "Number of boats required: " << result << endl;
return 0;
}