• 문제 링크
https://www.acmicpc.net/problem/13472
• 풀이 코드
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 = (int) read();
long[] arr = new long[n];
while (n-- > 0) arr[n] = read();
Arrays.sort(arr);
bw.write(isPossible(arr));
bw.flush();
}
private static String isPossible(long[] arr) {
for (int i = 2; i < arr.length; i++) if (arr[i - 2] + arr[i - 1] > arr[i]) return "possible";
return "impossible";
}
private static long read() throws IOException {
long c, n = System.in.read() & 15;
while ((c = System.in.read()) > 32) n = (n << 3) + (n << 1) + (c & 15);
return n;
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 4363 Snow Clearing - Graph Theory / Java (0) | 2024.08.14 |
---|---|
[백준] 6752 Time on task - Greedy / Java (0) | 2024.08.13 |
[백준] 23895 Allocation - Greedy / Java (0) | 2024.08.11 |
[백준] 9636 NASSA’s Robot - Greedy / Java (0) | 2024.08.10 |
[백준] 23731 Physics Experiment - Greedy / Java (0) | 2024.08.09 |
댓글