From 7f88479711e46458e755eabcbc383c5736362fae Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Thu, 6 Feb 2025 09:21:27 +0900 Subject: [PATCH] =?UTF-8?q?[20250206]=20BOJ=20/=20=EA=B3=A8=EB=93=9C3=20/?= =?UTF-8?q?=20=EA=B0=99=EC=9D=B4=20=EB=88=88=EC=82=AC=EB=9E=8C=20=EB=A7=8C?= =?UTF-8?q?=EB=93=A4=EB=9E=98=3F=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\247\214\353\223\244\353\236\230?.md" | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 "suyeun84/202502/06 BOJ G3 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230?.md" diff --git "a/suyeun84/202502/06 BOJ G3 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230?.md" "b/suyeun84/202502/06 BOJ G3 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230?.md" new file mode 100644 index 00000000..369f628a --- /dev/null +++ "b/suyeun84/202502/06 BOJ G3 \352\260\231\354\235\264 \353\210\210\354\202\254\353\236\214 \353\247\214\353\223\244\353\236\230?.md" @@ -0,0 +1,54 @@ +```java +import java.util.*; +import java.io.*; + +class Solution +{ + static int N; + static int[] len; + static int answer = Integer.MAX_VALUE; + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + len = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + len[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.sort(len); + + for (int i = 0; i < N; i++) { + for (int j = i+1; j < N; j++) { + calc(i, j); + if (answer == 0) { + System.out.println(0); + return; + } + } + } + if (answer == Integer.MAX_VALUE) System.out.println(0); + else System.out.println(answer); + } + + static void calc(int s1, int e1) { + int res = len[s1] + len[e1]; + int start = 0; + int end = N-1; + while (start < end) { + int cal = len[start] + len[end]; + if (s1 != start && e1 != end && s1 != end && e1 != start) { + answer = Math.min(answer, Math.abs(res-cal)); + } + if (res >= cal) { + start += 1; + } else { + end -= 1; + } + } + } +} + +```