File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments