프로그래머스 구명보트

최성현·2021년 2월 13일
0

백준 문제풀이

목록 보기
17/29

소스 코드

#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int solution(vector<int> people, int limit) {
    int answer = 0;

    int n = people.size();
    sort(people.begin(), people.end());
    int result = limit;
    int cnt = 1;
    int tail = 0; //제일작은
    int head = n - 1; //제일큰
    while (head >= tail) {
        result = limit;
        if (people[head] + people[tail] <= result) {
          
            tail++;
            head--;

        }
        else {
         
            head--;
        }
        cnt++;

    }



    return answer;
}
int main() {
    solution({ 70,50,80,50 }, 100);


    return 0;
}
profile
후회없이

0개의 댓글