-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_2473.java
More file actions
61 lines (42 loc) · 1.3 KB
/
baekjoon_2473.java
File metadata and controls
61 lines (42 loc) · 1.3 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import java.io.*;
import java.util.*;
public class baekjoon_2473 {
static long[] liquid;
static long MIN = Long.MAX_VALUE;
static int l1, l2, l3;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
liquid = new long[N];
for(int i=0;i<N;i++){
long a = Long.parseLong(st.nextToken());
liquid[i] = a;
}
Arrays.sort(liquid);
for(int i=0;i<N-2;i++){
twoPoint(i+1, liquid.length-1, i);
}
System.out.println(liquid[l1] + " " + liquid[l2] + " " + liquid[l3]);
}
public static void twoPoint(int p1, int p2, int fix){
long sum;
long abs;
while(p1<p2){
sum = liquid[p1] + liquid[p2] + liquid[fix];
abs = Math.abs(sum);
if(abs < MIN){
MIN = abs;
l1 = fix;
l2 = p1;
l3 = p2;
}
if(sum >= 0){
p2 -= 1;
}
else{
p1 += 1;
}
}
}
}