Skip to content

Commit 9cd3802

Browse files
authored
Merge pull request #455 from AlgorithmWithGod/suyeun84
[20250713] BOJ / G5 / 두 용액 / 김수연
2 parents af56b3b + 943205a commit 9cd3802

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj2470 {
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 = nextInt();
14+
int[] num = new int[N];
15+
nextLine();
16+
for (int i = 0; i < N; i++) num[i] = nextInt();
17+
Arrays.sort(num);
18+
19+
int check = Integer.MAX_VALUE;
20+
int answer1 = 0, answer2 = 0;
21+
int low = 0, high = N-1;
22+
23+
while(low<high) {
24+
int sum = num[low]+num[high];
25+
26+
if(Math.abs(sum)<check) {
27+
check = Math.abs(sum);
28+
answer1 = num[low];
29+
answer2 = num[high];
30+
}
31+
if(sum < 0) low++;
32+
else high--;
33+
}
34+
System.out.println(answer1+" "+answer2);
35+
}
36+
}
37+
```

0 commit comments

Comments
 (0)