-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJ_2473.java
More file actions
46 lines (41 loc) · 1.32 KB
/
BJ_2473.java
File metadata and controls
46 lines (41 loc) · 1.32 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
43
44
45
46
import java.io.*;
import java.util.*;
class BJ_2473 {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(reader.readLine());
long[] arr = new long[N];
StringTokenizer token = new StringTokenizer(reader.readLine());
for(int i=0; i<N; i++) {
arr[i] = Long.parseLong(token.nextToken());
}
Arrays.sort(arr);
long a = 0;
long b = 0;
long c = 0;
long min = Long.MAX_VALUE;
for(int i=0; i<N-2; i++) {
long fix = arr[i];
int left = i+1;
int right = N-1;
while(left<right) {
long sum = arr[left] + arr[right] + fix;
if(min > Math.abs(sum)) {
a = fix;
b = arr[left];
c = arr[right];
min = Math.abs(sum);
}
if(sum < 0) {
left++;
} else if(sum > 0) {
right--;
} else {
System.out.println(a + " " + b + " " + c);
System.exit(0);
}
}
}
System.out.println(a + " " + b + " " + c);
}
}