class Solution {
public:
int numRescueBoats(vector<int>& people, int limit)
{
sort(people.begin(), people.end());//升序排列
int start = 0, end = people.size() - 1, count = 0;
while (start<=end)
{
count++;
if (people[start] + people[end] <= limit)
{
start++;
end--;
}
else
end--;
}
return count;
}
};
int main()
{
vector<int> people = { 44, 10, 29, 12, 49, 41, 23, 5, 17, 26 };
int limit = 50;
Solution s;
cout << s.numRescueBoats(people, limit);
return 0;
}