문제 이해
알고리즘 구현
알고리즘
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
int n = people.size();
int end = n - 1;
int beg = 0;
sort(people.begin(), people.end(), greater<int>());
while (beg <= end) {
if (people[beg] + people[end] <= limit) {
++beg;
--end;
answer += 1;
}
else {
++beg;
answer += 1;
}
}
return answer;
}