From f9bae849cc04e0ec87f284960c86833f0ae211c0 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Fri, 19 Sep 2025 21:50:51 +0900 Subject: [PATCH] =?UTF-8?q?[20250919]=20BOJ=20/=20G5=20/=20=EB=91=90=20?= =?UTF-8?q?=EC=9A=A9=EC=95=A1=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... \353\221\220 \354\232\251\354\225\241.md" | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 "zinnnn37/202509/19 BOJ G5 \353\221\220 \354\232\251\354\225\241.md" diff --git "a/zinnnn37/202509/19 BOJ G5 \353\221\220 \354\232\251\354\225\241.md" "b/zinnnn37/202509/19 BOJ G5 \353\221\220 \354\232\251\354\225\241.md" new file mode 100644 index 00000000..d567c9cd --- /dev/null +++ "b/zinnnn37/202509/19 BOJ G5 \353\221\220 \354\232\251\354\225\241.md" @@ -0,0 +1,65 @@ +```java +import java.io.*; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class BJ_2470_두_용액 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int N; + private static int tmp; + private static int[] ans; + private static int[] solution; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + tmp = Integer.MAX_VALUE; + + ans = new int[2]; + solution = new int[N]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < N; i++) { + solution[i] = Integer.parseInt(st.nextToken()); + } + Arrays.sort(solution); + } + + private static void sol() throws IOException { + int left = 0, right = N - 1; + + while (left < right) { + int sum = solution[left] + solution[right]; + + if (Math.abs(sum) <= tmp) { + ans[0] = solution[left]; + ans[1] = solution[right]; + + tmp = Math.abs(sum); + + if (sum == 0) { + break; + } + } + + if (sum < 0) { + left++; + } else { + right--; + } + } + bw.write(ans[0] + " " + ans[1]); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file