풀스택 개발자 2021. 4. 13. 19:26
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int solution(vector<int> people, int limit) {
   sort(people.begin(), people.end());
   
    int answer = 0, idx = 0;
    
    while(people.size() > idx){
        int back = people.back(); 
		people.pop_back();
        if(people[idx] + back <= limit){
		 	answer++; 
			idx++; 
		 }
        else
		{
			answer++;
		}
    }
    return answer;
}

int main()
{
	vector<int> people;
	 int limit = 100;

	people.push_back(70);
	people.push_back(50);
	people.push_back(80);
	people.push_back(50);
	
	
	
	cout << solution(people,limit);

}