Skip to content

Commit a95dcb9

Browse files
authored
Merge pull request #1466 from AlgorithmWithGod/ksinji
[20251121] BOJ / G5 / 빗물 / 강신지
2 parents 4226e9b + a726d75 commit a95dcb9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

ksinji/202511/21 BOJ 빗물.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
StringTokenizer st = new StringTokenizer(br.readLine());
9+
10+
int h = Integer.parseInt(st.nextToken());
11+
int w = Integer.parseInt(st.nextToken());
12+
13+
int[] height = new int[w];
14+
15+
st = new StringTokenizer(br.readLine());
16+
for (int i=0; i<w; i++){
17+
height[i] = Integer.parseInt(st.nextToken());
18+
}
19+
20+
int answer=0, l=0;
21+
22+
for (int i=1; i<w-1; i++){
23+
l = Math.max(l, height[i-1]);
24+
int r = 0;
25+
for (int j=i+1; j<w; j++){
26+
r = Math.max(r, height[j]);
27+
}
28+
29+
if (height[i] < l && height[i] < r) answer+=Math.min(l, r)-height[i];
30+
}
31+
32+
System.out.println(answer);
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)