Skip to content

Commit b01af57

Browse files
authored
[20250808] BOJ / G5 / 빗물 / 이인희
1 parent e0c56cc commit b01af57

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
public class Main {
5+
private static BufferedReader br;
6+
private static int H, W;
7+
private static int[] Walls;
8+
private static StringTokenizer st;
9+
public static void main(String[] args) throws IOException {
10+
br = new BufferedReader(new InputStreamReader(System.in));
11+
String[] temp = br.readLine().split(" ");
12+
H = Integer.parseInt(temp[0]);
13+
W = Integer.parseInt(temp[1]);
14+
15+
st = new StringTokenizer(br.readLine());
16+
int answer = 0;
17+
int sum = 0;
18+
19+
int leftH = Integer.parseInt(st.nextToken());
20+
for(int w = 1; w<W; w++) {
21+
int wall = Integer.parseInt(st.nextToken());
22+
if(wall < leftH) {
23+
sum += leftH - wall;
24+
continue;
25+
}
26+
leftH = wall;
27+
answer += sum;
28+
sum = 0;
29+
}
30+
answer -= sum;
31+
System.out.println(answer);
32+
br.close();
33+
34+
}
35+
}
36+
```

0 commit comments

Comments
 (0)