-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path빗물.java
More file actions
42 lines (36 loc) · 1.32 KB
/
빗물.java
File metadata and controls
42 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
import java.util.*;
public class Main {
static int h, w;
static int[] map;
static StringTokenizer st;
static StringBuilder sb;
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String[] args) throws Exception{
pre_setting();
bw.append(sb.append(rain_check()));
bw.close();
}
private static int rain_check() {
int ans, left, right;
ans = 0;
for(int now = 1; now < w - 1; now++){
left = 0;
right = 0;
for (int l = 0; l < now; l++) left = Math.max(map[l], left);
for (int r = now + 1; r < w; r++) right = Math.max(map[r], right);
ans += Math.max(Math.min(left, right) - map[now], 0);
}
return ans;
}
private static void pre_setting() throws Exception{
sb = new StringBuilder();
st = new StringTokenizer(br.readLine());
h = Integer.parseInt(st.nextToken());
w = Integer.parseInt(st.nextToken());
map = new int[w];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < w; i++) map[i] = Integer.parseInt(st.nextToken());
}
}