Skip to content

Commit a7dc870

Browse files
authored
[20251017] BOJ / G5 / 용앱 합성하기 / 이준희
1 parent 2135027 commit a7dc870

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 Main {
6+
7+
public static void main(String[] args) throws IOException {
8+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
StringTokenizer st;
10+
11+
int n = Integer.parseInt(br.readLine());
12+
13+
int[] arr = new int[n];
14+
15+
st = new StringTokenizer(br.readLine());
16+
17+
for (int i = 0; i < n; i++) {
18+
arr[i] = Integer.parseInt(st.nextToken());
19+
}
20+
21+
int left = 0;
22+
int right = n - 1;
23+
int temp = 987654321;
24+
int res = 0;
25+
26+
while (left < right) {
27+
int sum = arr[left] + arr[right];
28+
if (sum < 0) {
29+
left++;
30+
} else if (sum > 0) {
31+
right--;
32+
} else {
33+
res = 0;
34+
break;
35+
}
36+
if(temp> Math.abs(sum)){
37+
res = sum;
38+
temp = Math.abs(sum);
39+
}
40+
}
41+
42+
System.out.println(res);
43+
}
44+
}
45+
```

0 commit comments

Comments
 (0)