Problem Solving/Baekjoon
[백준] 16200 해커톤 - Greedy / Java
graycode
2024. 2. 13. 10:32
• 문제 링크
16200번: 해커톤
예를 들어, 5명의 학생이 있고, X1 = 1, X2 = 2, X3 = 5, X4 = 2, X5 = 1인 경우에 팀의 수의 최솟값은 4이다. {1}, {2}, {3}, {4}, {5}로 5개의 팀을 만드는 방법이 있지만, 이것은 팀의 수가 최소가 아니다. {1}, {3}
www.acmicpc.net
• 풀이 코드
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws IOException {
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int n = read();
int[] arr = new int[n];
while (n-- > 0) arr[n] = read();
Arrays.sort(arr);
int cnt = 0;
for (int i = 0; i < arr.length; i += arr[i]) cnt++;
bw.write(String.valueOf(cnt));
bw.flush();
}
private static int read() throws IOException {
int c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}