Skip to content

Commit cd0ddca

Browse files
authored
Merge pull request #484 from AlgorithmWithGod/suyeun84
[20250717] BOJ / G5 / 두 개의 탑 / 김수연
2 parents e59e845 + 49e0053 commit cd0ddca

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj2118 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
int sum = 0;
15+
int[] dist = new int[N+1];
16+
17+
for(int i=0;i<N;i++){
18+
nextLine();
19+
dist[i] = nextInt();
20+
sum += dist[i];
21+
}
22+
23+
int start = 0, last = 0, result = 0;
24+
int now = dist[start];
25+
26+
while(start <= last && last < N){
27+
int minNow = Integer.min(now,sum - now);
28+
result = Integer.max(result, minNow);
29+
if(now == minNow){
30+
last++;
31+
now += dist[last];
32+
}
33+
else{
34+
now -= dist[start];
35+
start++;
36+
}
37+
}
38+
System.out.println(result);
39+
}
40+
}
41+
```

0 commit comments

Comments
 (0)