C++:: 프로그래머스 < 예산 >

jahlee·2023년 7월 21일
0

프로그래머스_Lv.1

목록 보기
45/75
post-thumbnail

단순히 예산범위 내에서 최대 지원 가능한 수를 구하면 되는 간단한 문제이다.

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

int solution(vector<int> d, int budget) {
    int answer = 0;
    sort(d.begin(), d.end());// 오름차순 정렬
    for (auto c : d) {
        if (c > budget) break;
        budget -= c;
        answer++;
    }
    return answer;
}

1개의 댓글

comment-user-thumbnail
2023년 7월 21일

잘 읽었습니다. 좋은 정보 감사드립니다.

답글 달기