Skip to content

Commit 191ed2f

Browse files
authored
Merge pull request #172 from AlgorithmWithGod/khj20006
[20250225] BOJ / S2 / 창고 다각형 / 권혁준
2 parents 717146b + 8cdb072 commit 191ed2f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```cpp
2+
3+
#include <iostream>
4+
#include <algorithm>
5+
using namespace std;
6+
7+
int main()
8+
{
9+
cin.tie(0)->sync_with_stdio(0);
10+
11+
int N, Y[1001]{}, Z[1001]{};
12+
cin >> N;
13+
for (int i = 0, a, b; i < N; i++) {
14+
cin >> a >> b;
15+
Y[a] = b;
16+
}
17+
18+
for (int i = 1; i <= 1000; i++) Z[i] = max(Z[i - 1], Y[i]);
19+
20+
int ans = 0, from_right = 0;
21+
for (int i = 1000; i >= 1; i--) {
22+
from_right = max(from_right, Y[i]);
23+
Z[i] = min(Z[i], from_right);
24+
ans += Z[i];
25+
}
26+
cout << ans;
27+
28+
}
29+
30+
```

0 commit comments

Comments
 (0)