
#include <vector>
#include <algorithm>
using namespace std;
int solution(vector<int> d, int budget) {
int answer = 0;
// 예산 안에서 최대한 많은 "부서" count개의 물품 구매하기
// 따라서 오름차순 정렬, 신청 금액이 적은 부서부터 지원
sort(d.begin(), d.end());
for (int i = 0; i < d.size(); i++)
{
if (0 <= (budget -= d[i])) {
answer++;
}
}
return answer;
}
https://learn.microsoft.com/ko-kr/cpp/standard-library/algorithm-functions?view=msvc-170#sort
https://zoosso.tistory.com/1086
지정된 범위에 있는 요소를 비내림차순 또는 이진 조건자로 지정한 정렬 기준에 따라 정렬한다
#include <algorithm>
void sort(T first, T last);
void sort(T first, T last, Compare pred);