Skip to content

Commit 26d524e

Browse files
authored
Merge pull request #1874 from AlgorithmWithGod/LiiNi-coder
[20260202] BOJ / G5 / 용액 / 이인희
2 parents b354abb + 08493bc commit 26d524e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.StringTokenizer;
6+
7+
public class Main {
8+
public static void main(String[] args) throws IOException {
9+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
int n = Integer.parseInt(br.readLine());
11+
long[] arr = new long[n];
12+
StringTokenizer st = new StringTokenizer(br.readLine());
13+
for (int i = 0; i < n; i++) {
14+
arr[i] = Long.parseLong(st.nextToken());
15+
}
16+
int l = 0;
17+
int r = n - 1;
18+
long bestA = arr[l];
19+
long bestB = arr[r];
20+
long bestAbs = Math.abs(arr[l] + arr[r]);
21+
22+
while (l < r) {
23+
long sum = arr[l] + arr[r];
24+
long absSum = Math.abs(sum);
25+
if (absSum < bestAbs) {
26+
bestAbs = absSum;
27+
bestA = arr[l];
28+
bestB = arr[r];
29+
}
30+
if (sum > 0) {
31+
r--;
32+
} else {
33+
l++;
34+
}
35+
}
36+
System.out.println(bestA + " " + bestB);
37+
}
38+
}
39+
40+
```

0 commit comments

Comments
 (0)