Skip to content

Commit 09b81bc

Browse files
authored
[20250612] BOJ / G3 / 세 용액 / 김수연
1 parent 6959e78 commit 09b81bc

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj2473 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = Integer.parseInt(st.nextToken());
14+
long[] num = new long[N];
15+
long answer = Long.MAX_VALUE;
16+
long[] res = new long[3];
17+
nextLine();
18+
for(int i = 0; i < N; i++) {
19+
num[i] = Long.parseLong(st.nextToken());
20+
}
21+
Arrays.sort(num);
22+
23+
for (int i = 0; i < N; i++) {
24+
int start = i+1;
25+
int end = N-1;
26+
while (start < end) {
27+
long temp = num[i] + num[start] + num[end];
28+
if (Math.abs(temp) < answer) {
29+
res[0] = num[i];
30+
res[1] = num[start];
31+
res[2] = num[end];
32+
answer = Math.abs(temp);
33+
}
34+
if (temp > 0) end--;
35+
else if (temp < 0) start++;
36+
else {
37+
System.out.println(res[0]+" "+res[1]+" "+res[2]);
38+
return;
39+
}
40+
}
41+
}
42+
System.out.println(res[0]+" "+res[1]+" "+res[2]);
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)