-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_2470.java
More file actions
41 lines (32 loc) · 855 Bytes
/
baekjoon_2470.java
File metadata and controls
41 lines (32 loc) · 855 Bytes
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
import java.util.*;
import java.io.*;
public class baekjoon_2470 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
long[] nums = new long[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < N; i++) {
nums[i] = Long.parseLong(st.nextToken());
}
Arrays.sort(nums);
long[] res = new long[2];
int left = 0;
int right = N - 1;
long min = Integer.MAX_VALUE;
while (left < right) {
long sum = nums[left] + nums[right];
if (min > Math.abs(sum)) {
min = Math.abs(sum);
res[0] = nums[left];
res[1] = nums[right];
}
if (sum == 0) break;
else if (sum < 0) left++;
else right--;
}
for (long r : res) {
System.out.print(r + " ");
}
}
}