https://programmers.co.kr/learn/courses/30/lessons/42885#
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
int answer = 0;
int idx = 0;
sort(people.begin(), people.end());
for(int i= people.size()-1;i>=0;i--){
if(idx == i){
return ++answer;
}else if(idx >i)
return answer;
if(people[idx] + people[i] <= limit){
idx++;
}
answer++;
}
}
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> people, int limit) {
sort(people.begin(), people.end());
reverse(people.begin(), people.end());
int N = (int)people.size();
int res = 0;
for (int i = 0, j = N - 1; i <= j; i++) {
if (people[i] + people[j] <= limit) {
j--;
}
res++;
}
return res;
}