diff --git "a/zinnnn37/202511/21 BJ G5 \353\271\227\353\254\274.md" "b/zinnnn37/202511/21 BJ G5 \353\271\227\353\254\274.md" new file mode 100644 index 00000000..8894040c --- /dev/null +++ "b/zinnnn37/202511/21 BJ G5 \353\271\227\353\254\274.md" @@ -0,0 +1,61 @@ +```java +import java.io.*; +import java.util.StringTokenizer; + +public class BJ_14719_빗물 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static StringTokenizer st; + + private static int H, W; + private static int[] height; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + H = Integer.parseInt(st.nextToken()); + W = Integer.parseInt(st.nextToken()); + + height = new int[W]; + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < W; i++) { + height[i] = Integer.parseInt(st.nextToken()); + } + } + + private static void sol() throws IOException { + int left = 0, right = W - 1; + int leftMax = 0, rightMax = 0; + int result = 0; + + while (left < right) { + if (height[left] < height[right]) { + if (height[left] >= leftMax) { + leftMax = height[left]; + } else { + result += leftMax - height[left]; + } + left++; + } else { + if (height[right] >= rightMax) { + rightMax = height[right]; + } else { + result += rightMax - height[right]; + } + right--; + } + } + + bw.write(String.valueOf(result)); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file