Skip to content

Commit

Permalink
[solved] boj2467
Browse files Browse the repository at this point in the history
  • Loading branch information
leetaggg committed Oct 26, 2023
1 parent 1fa1b13 commit 1cf69fa
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions LeeTaeHo/boj/boj2467.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import java.io.*;
import java.util.*;

public class boj2467 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(br.readLine());

StringTokenizer st = new StringTokenizer(br.readLine());

int[] arr = new int[n];

for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}

int left = 0;
int right = arr.length - 1;
int sum = 0;

int resultLeft = 0;
int resultRight = 0;
int minValue = Integer.MAX_VALUE;

while(left < right){
sum = arr[left] + arr[right];
if(Math.abs(minValue) > Math.abs(sum)){
minValue = sum;
resultLeft = left;
resultRight = right;
}
if(sum == 0){
break;
}else if(sum < 0){
left++;
}else{
right--;
}
}
System.out.println(arr[resultLeft] + " " + arr[resultRight]);
}
}

0 comments on commit 1cf69fa

Please sign in to comment.