Skip to content

Commit f13680e

Browse files
authored
Merge pull request #47 from AlgorithmWithGod/suyeun84
[20250206] BOJ / 골드3 / 같이 눈사람 만들래? / 김수연
2 parents 0912970 + 7f88479 commit f13680e

File tree

1 file changed

+54
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)