#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]) { break; } else { budget -= d[i]; answer++; } } return answer; } | cs |
'Programmers > Level 1' 카테고리의 다른 글
[프로그래머스 1] 직사각형 별찍기 (C/C++) (0) | 2019.10.19 |
---|---|
[프로그래머스 1] x만큼 간격이 있는 n개의 숫자 (C/C++) (0) | 2019.10.19 |
[프로그래머스 1] 행렬의 덧셈 (C/C++) (0) | 2019.10.19 |
[프로그래머스 1] 핸드폰 번호 가리기 (C/C++) (0) | 2019.10.19 |
[프로그래머스 1] 하샤드 수 (C/C++) (0) | 2019.10.19 |