Skip to content

Commit

Permalink
Merge pull request #50 from ParkJaeRim/baekjoon
Browse files Browse the repository at this point in the history
Study on 210405
  • Loading branch information
ParkJaeRim authored Apr 5, 2021
2 parents 3e041db + e79ba62 commit a1fa1ed
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions April/boj_14719_빗물.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class boj_14719_빗물 {
static int[] wall;
static int water;

public static void main(String[] args) throws IOException {

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());

int H = Integer.parseInt(st.nextToken());
int W = Integer.parseInt(st.nextToken());
wall = new int[W];
st = new StringTokenizer(br.readLine());
water = 0;
int i = 0;
while (st.hasMoreTokens()) {
wall[i++] = Integer.parseInt(st.nextToken());
}

for (int idx = 0; idx < wall.length; idx++) {
int leftMax = wall[idx];
int rightMax = wall[idx];
for (int left = 0; left < idx; left++) {
leftMax = Math.max(leftMax, wall[left]);
}

for (int right = idx + 1; right < wall.length; right++) {
rightMax = Math.max(rightMax, wall[right]);
}

if (leftMax <= wall[idx] || rightMax <= wall[idx]) {
continue;
} else {
if (leftMax > rightMax) {
water += rightMax - wall[idx];
} else {
water += leftMax - wall[idx];
}
}
}
System.out.println(water);
}
}

0 comments on commit a1fa1ed

Please sign in to comment.