Skip to content

Commit da24107

Browse files
authored
Merge pull request #1487 from AlgorithmWithGod/ksinji
[20251123] BOJ / G5 / 용액 / 강신지
2 parents 6872674 + 0e0cd5f commit da24107

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

ksinji/202511/23 BOJ 용액.md

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

0 commit comments

Comments
 (0)