코딩테스트/프로그래머스 - LV 1

[프로그래머스] 예산

웅드 2024. 2. 9. 17:07

 

  • 풀이
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int solution(vector<int> d, int budget) {
    int answer = 0;
    
    sort(d.begin(),d.end());
    for(int i=0; i<d.size(); i++){
        if(budget-d[i]<0) break;
        answer++;
        budget-=d[i];
    }
    
    return answer;
}
반응형