프로그래머스 - 예산

well-life-gm·2021년 11월 25일
0

프로그래머스

목록 보기
64/125

프로그래머스 - 예산

레벨 1짜리 문제다.

#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> d, int budget) {
    int answer = 0;
    int ac = 0;
    sort(d.begin(), d.end());
    for(auto it : d) {
        if(ac + it > budget)
            break;
        ac += it;
        answer++;
    }
    return answer;
}
profile
내가 보려고 만든 블로그

0개의 댓글