20251104 baekjoon

This commit is contained in:
songyc macbook 2025-11-04 20:48:39 +09:00
parent 34cef97753
commit 7d386a1532

View File

@ -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);
}
}