[BOJ 2467] ์ฉ์ก
1. ๋ฌธ์ : https://www.acmicpc.net/problem/2110
2. ํ์ด
ํฌํฌ์ธํฐ ํ์ด, l, r ๋ชจ๋ ์ ์ฅํด์ค์ผํจ
3. ์ฝ๋
package baekjoon;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
long[] arr = new long[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i=0; i<n; i++) {
arr[i] = Long.parseLong(st.nextToken());
}
int left =0;
int right =n-1;
int ml =0, mr = 0;
long min = Long.MAX_VALUE;
while(left<right) {
long sum = arr[left]+arr[right];
if(min > Math.abs(sum)) {
min = Math.abs(sum);
ml = left; mr = right;
}
if(sum>=0) {
right--;
}else {
left++;
}
}
System.out.println(arr[ml] +" "+arr[mr]);
}
}
'๐ป Coding Problems Solving > Two Pointers | Binary Search| LinkedList' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[BOJ 1515] ์์ด์ด์ฐ๊ธฐ (0) | 2023.09.14 |
---|---|
[BOJ 2110] ๊ณต์ ๊ธฐ ์ค์น (0) | 2023.09.06 |
[BOJ 2343] ๊ธฐํ ๋ ์จ (0) | 2023.09.05 |
[BOJ 19637] IF๋ฌธ ์ข ๋์ ์จ์ค (0) | 2023.08.31 |
[BOJ 2512] ์์ฐ (0) | 2023.08.27 |
์ต๊ทผ๋๊ธ