-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2304.cpp
75 lines (66 loc) · 1.3 KB
/
2304.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 2304. 창고 다각형
// 2020.12.18
// 스택
#include<iostream>
#include<stack>
using namespace std;
stack<int> st;
int column[1001];
int first = 1001;
int last;
int maxPos;
int ans;
int main()
{
int pos;
int height;
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> pos >> height;
column[pos] = height;
if (last < pos)
{
last = pos;
}
if (first > pos)
{
first = pos;
}
if (height > column[maxPos])
{
maxPos = pos;
}
}
// 최초 기둥이 있는 지점부터 가장 높은 지점까지 넓이 구함
for (int i = first; i <= maxPos; i++)
{
if (column[i])
{
if (st.empty() || column[i] > st.top())
{
st.push(column[i]);
}
}
ans += st.top();
}
while (!st.empty())
{
st.pop();
}
// 맨뒤 기둥이 있는 지점부터 가장 높은 지점까지 넓이 구함
for (int i = last; i > maxPos; i--)
{
if (column[i])
{
if (st.empty() || column[i] > st.top())
{
st.push(column[i]);
}
}
ans += st.top();
}
cout << ans << endl;
return 0;
}