• 문제 링크
10263번: Opening Ceremony
The first line of input contains the number of blocks n, where 2 ≤ n ≤ 100 000. The second line contains n consecutive block heights hi for i = 1, 2, ... , n, where 1 ≤ hi ≤ 1 000 000.
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];
for (int i = 0; i < n; i++) arr[i] = read();
Arrays.sort(arr);
int min = n--;
for (int i = n; i >= 0; i--) min = Math.min(min, arr[i] + n - i);
bw.write(String.valueOf(min));
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' 카테고리의 다른 글
[백준] 25287 순열 정렬 - Greedy / Java (0) | 2024.01.14 |
---|---|
[백준] 2864 5와 6의 차이 - Greedy / Java (0) | 2024.01.13 |
[백준] 10774 저지 - Greedy / Java (0) | 2024.01.11 |
[백준] 5991 Papaya Jungle - Graph Theory / Java (0) | 2024.01.10 |
[백준] 26999 Satellite Photographs - Graph Theory / Java (0) | 2024.01.09 |
댓글