• 문제 링크
28110번: 마지막 문제
때는 3023년, PPC 출제진들은 심혈을 기울여 PPC에 출제할 $N$개의 문제를 정했다. 각 문제는 $1$ 이상 $10^9$ 이하의 정수로 표현되는 난이도를 가지고 있으며, $N$개의 문제에 대한 난이도는 모두 다르
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 max = 0, res = -1;
for (int i = 1; i < n; i++) {
int diff = (arr[i] - arr[i - 1]) / 2;
if (max < diff) {
max = diff;
res = (arr[i] + arr[i - 1]) / 2;
}
}
bw.write(String.valueOf(res));
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' 카테고리의 다른 글
[백준] 15600 Boss Battle - Greedy / Java (0) | 2024.03.14 |
---|---|
[백준] 30236 증가 수열 - Greedy / Java (0) | 2024.03.13 |
[백준] 9329 패스트 푸드 상금 - Greedy / Java (0) | 2024.03.11 |
[백준] 9372 상근이의 여행 - Graph Theory / Java (0) | 2024.03.10 |
[백준] 22035 Bus Lines - Graph Theory / Java (0) | 2024.03.09 |
댓글