-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2467_์ฉ์ก.java
More file actions
42 lines (35 loc) ยท 1.35 KB
/
2467_์ฉ์ก.java
File metadata and controls
42 lines (35 loc) ยท 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int N, min;
static int[] res = new int[2];
static int[] arr;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
N = Integer.parseInt(br.readLine());
arr = new int[N];
st = new StringTokenizer(br.readLine());
for(int i=0; i<N; i++) { //์
๋ ฅ
arr[i] = Integer.parseInt(st.nextToken());
}
min = Integer.MAX_VALUE;
//ํฌ ํฌ์ธํฐ
int lp = 0;
int rp = N-1;
while(lp != N && rp != -1 && lp != rp) { //๋ฐฐ์ด ๋์ ํ์ํ๊ฑฐ๋ ํฌ์ธํฐ๊ฐ ๋์ผํด์ง ๊ฒฝ์ฐ
long diff = arr[lp] + arr[rp];
if(Math.abs(diff) < min) { //์ต์๊ฐ์ ์ฐพ์ ๊ฒฝ์ฐ ๊ฐ ๊ฐฑ์
res[0] = arr[lp];
res[1] = arr[rp];
min = (int) Math.abs(diff);
}
if(diff == 0) break; //ํฉ์ด 0์ผ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
else if(diff < 0) lp++; //๋ ์์ ํฉ์ด ์์์ผ ๊ฒฝ์ฐ ์์๊ฐ ์ฆ๊ฐ
else rp--; //๋ ์์ ํฉ์ด ์์์ผ ๊ฒฝ์ฐ ์์๊ฐ ๊ฐ์
}
System.out.println(res[0] + " " + res[1]);
}
}