• 문제 링크
15761번: Lemonade Line
It's a hot summer day out on the farm, and Farmer John is serving lemonade to his $N$ cows! All $N$ cows (conveniently numbered $1 \dots N$) like lemonade, but some of them like it more than others. In particular, cow $i$ is willing to wait in a line behin
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[] arr = new int[read()];
for (int i = 0; i < arr.length; i++) arr[i] = read();
Arrays.sort(arr);
int cnt = 0;
for (int i = arr.length - 1; i >= 0; i--, cnt++) if (arr[i] < cnt) break;
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;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 16406 Exam - Greedy / Java (0) | 2023.12.21 |
---|---|
[백준] 20974 Even More Odd Photos - Greedy / Java (0) | 2023.12.20 |
[백준] 28323 불안정한 수열 - Greedy / Java (0) | 2023.12.18 |
[백준] 4993 Red and Black - Graph Theory / Java (0) | 2023.12.17 |
[백준] 15242 Knight - Graph Theory / Java (0) | 2023.12.16 |
댓글