Skip to content

Commit 9723289

Browse files
authored
Merge pull request #950 from AlgorithmWithGod/0224LJH
[20250922] BOJ / G5 / 두 개의 탑 / 이종환
2 parents c9e5823 + b9ffde1 commit 9723289

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
import java.util.*;
6+
7+
public class Main {
8+
9+
static int nodeCnt, sum,ans;
10+
static int[] arr;
11+
12+
public static void main(String[] args) throws NumberFormatException, IOException {
13+
init();
14+
process();
15+
print();
16+
17+
18+
}
19+
20+
public static void init() throws NumberFormatException, IOException {
21+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
22+
nodeCnt = Integer.parseInt(br.readLine());
23+
arr = new int[nodeCnt];
24+
ans = 0;
25+
for (int i = 0; i < nodeCnt; i++) {
26+
arr[i] = Integer.parseInt(br.readLine());
27+
sum += arr[i];
28+
}
29+
30+
}
31+
32+
public static void process() {
33+
int halfSum =sum/2;
34+
int st = 0;
35+
int end = 0;
36+
37+
int curSum = arr[0];
38+
39+
40+
while(true) {
41+
ans = Math.max(ans, Math.min(curSum, sum - curSum));
42+
if (curSum <= halfSum) {
43+
end++;
44+
45+
if (end >= nodeCnt) break;
46+
curSum += arr[end];
47+
} else {
48+
curSum -=arr[st];
49+
st++;
50+
}
51+
52+
}
53+
54+
}
55+
56+
57+
58+
public static void print() {
59+
System.out.println(ans);
60+
}
61+
}
62+
```

0 commit comments

Comments
 (0)