본문 바로가기

컴퓨터공학

[프로그래머스, C++] 예산

반응형
#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 i=0;
    sort(d.begin(),d.end());
    while(answer<=budget and i<=d.size()){
        answer+=d[i];
        i++;
        cout<<answer<<" ";
    }
    
    return i-1;
}
반응형