Computer Science/Coding Test
c++(cpp) 프로그래머스 - 코딩테스트 : 예산
hzyiunn
2022. 8. 11. 01:26
728x90
반응형
#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;
}
else
{
budget = budget - d[i];
answer++;
}
}
return answer;
}
728x90
반응형