Skip to content

Commit d134374

Browse files
authored
Merge pull request #643 from AlgorithmWithGod/lkhyun
[20250810] BOJ / G4 / 세수의 합 / 이강현
2 parents a61532e + f9e1a17 commit d134374

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static int N;
9+
static int[] arr;
10+
11+
public static void main(String[] args) throws Exception {
12+
N = Integer.parseInt(br.readLine());
13+
arr = new int[N];
14+
15+
for (int i = 0; i < N; i++) {
16+
arr[i] = Integer.parseInt(br.readLine());
17+
}
18+
Arrays.sort(arr);
19+
20+
Set<Integer> sums = new HashSet<>();
21+
for (int i = 0; i < N; i++) {
22+
for (int j = 0; j < N; j++) {
23+
sums.add(arr[i] + arr[j]);
24+
}
25+
}
26+
27+
a: for (int i = N-1; i >= 0; i--) {
28+
for (int j = 0; j <= i; j++) {
29+
if(sums.contains(arr[i] - arr[j])){
30+
bw.write(arr[i] + "");
31+
break a;
32+
}
33+
}
34+
}
35+
bw.close();
36+
}
37+
}
38+
```

0 commit comments

Comments
 (0)