[프로그래머스, 12982] 예산 (java)
Problem Solving/Programmers

[프로그래머스, 12982] 예산 (java)

728x90

https://school.programmers.co.kr/learn/courses/30/lessons/12982

 

프로그래머스

SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프

programmers.co.kr

728x90

메모리: 87.5 MB, 시간: 0.55 ms

사용 알고리즘: 정렬

import java.util.*;

class Solution {
    public int solution(int[] d, int budget) {
        
        int answer = 0;
        
        // 정렬
        Arrays.sort(d);
        
        // 지급 가능한 부서 개수 세기
        for(int price : d) {
            if(budget >= price) {
                answer++;
                budget -= price;
            }
        }
        
        return answer;
    }
}
728x90