문제풀이/백준
백준 14719 - 빗물
레옹
2021. 11. 24. 20:59
https://www.acmicpc.net/problem/14719
14719번: 빗물
첫 번째 줄에는 2차원 세계의 세로 길이 H과 2차원 세계의 가로 길이 W가 주어진다. (1 ≤ H, W ≤ 500) 두 번째 줄에는 블록이 쌓인 높이를 의미하는 0이상 H이하의 정수가 2차원 세계의 맨 왼쪽 위치
www.acmicpc.net
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int H, W;
int Block[510];
int main() {
scanf("%d", &H);
scanf("%d", &W);
for (int i = 0; i < W; i++) {
scanf("%d", &Block[i]);
}
int totalRain = 0;
for (int h = 1; h <= H; h++) {
int wall = -1;
int length = 0;
for (int w = 0; w < W; w++) {
if (Block[w] >= h) {
if(wall != -1)
totalRain += max((w - wall - 1), 0);
wall = w;
}
}
}
printf("%d", totalRain);
return 0;
}
정말 간단한 문제였는데... 삽질해서 푸는데 오래걸렸다.