Notice
Recent Posts
Recent Comments
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
Tags
more
Archives
Today
Total
관리 메뉴

forDevLife

[이코테]모험가 길드 <그리디> 본문

알고리즘

[이코테]모험가 길드 <그리디>

JH_Lucid 2021. 5. 3. 13:02
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int N = Integer.parseInt(br.readLine());
        int[] people = new int[N];

        StringTokenizer st = new StringTokenizer(br.readLine(), " ");
        for(int i=0; i< N; i++) {
            people[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(people);

        int count = 0;
        int group_cnt = 0; //그룹 최소 인원

        for(int i=0; i<N; i++) {
            group_cnt ++;
            if(group_cnt == people[i]) {
                count++;
                group_cnt = 0;
            }
        }
        System.out.println(count);
    }
}
Comments