๋ฌธ์
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ์์ฐ
S์ฌ์์๋ ๊ฐ ๋ถ์์ ํ์ํ ๋ฌผํ์ ์ง์ํด ์ฃผ๊ธฐ ์ํด ๋ถ์๋ณ๋ก ๋ฌผํ์ ๊ตฌ๋งคํ๋๋ฐ ํ์ํ ๊ธ์ก์ ์กฐ์ฌํ์ต๋๋ค. ๊ทธ๋ฌ๋, ์ ์ฒด ์์ฐ์ด ์ ํด์ ธ ์๊ธฐ ๋๋ฌธ์ ๋ชจ๋ ๋ถ์์ ๋ฌผํ์ ๊ตฌ๋งคํด ์ค ์๋
programmers.co.kr
์ฝ๋
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
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++){
budget-=d[i];
if(budget<0) break;
answer++;
}
return answer;
}
๋๊ธ