-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14719(Simulation).java
More file actions
53 lines (45 loc) · 1.5 KB
/
14719(Simulation).java
File metadata and controls
53 lines (45 loc) · 1.5 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
43
44
45
46
47
48
49
50
51
52
53
import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
StringTokenizer st;
st = new StringTokenizer(br.readLine());
int H = Integer.parseInt(st.nextToken());
int W = Integer.parseInt(st.nextToken());
int block[][] = new int[H][W];
st = new StringTokenizer(br.readLine());
for(int i = 0; i < W; i++) {
int temp = Integer.parseInt(st.nextToken());
for(int j = 0; j < temp; j++){
block[j][i] = 1;
}
}
int sum = 0;
for(int i = 0; i < H; i++) {
for(int j = 1; j < W; j++) {
if(block[i][j] != 1 && block[i][j - 1] == 1) {
int end = j;
boolean flag = false;
int count = 0;
while (true) {
if(end == W){
break;
}
if(block[i][end] == 1){
flag = true;
break;
}
end++;
count++;
}
if(flag) {
sum += count;
}
}
}
}
System.out.println(sum);
}
}