From 7d386a1532eaf844dabd4ef9098c73cbca4e683e Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Tue, 4 Nov 2025 20:48:39 +0900 Subject: [PATCH] 20251104 baekjoon --- code_study/Baekjoon/java/_2467.java | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 code_study/Baekjoon/java/_2467.java diff --git a/code_study/Baekjoon/java/_2467.java b/code_study/Baekjoon/java/_2467.java new file mode 100644 index 0000000..d66f6a4 --- /dev/null +++ b/code_study/Baekjoon/java/_2467.java @@ -0,0 +1,31 @@ +import java.util.*; + +public class _2467 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int N = Integer.parseInt(sc.nextLine()); + int[] nums = Arrays.stream(sc.nextLine().split(" ")) + .mapToInt(Integer::parseInt) + .toArray(); + sc.close(); + + int pL = 0, pR = N-1; + int value = Math.abs(nums[pL] + nums[pR]); + int resA = nums[pL], resB = nums[pR]; + + while(pL < pR) { + int temp = nums[pL] + nums[pR]; + + if(Math.abs(temp) < value) { + value = Math.abs(temp); + resA = nums[pL]; + resB = nums[pR]; + } + + if(temp < 0) pL++; + else pR--; + } + + System.out.printf("%d %d\n",resA, resB); + } +}