20251104 baekjoon
This commit is contained in:
parent
34cef97753
commit
7d386a1532
31
code_study/Baekjoon/java/_2467.java
Normal file
31
code_study/Baekjoon/java/_2467.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user