From c58a92afdc34a92586887de4f72fc1408f920d7d Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 1 Sep 2026 15:46:35 +0900 Subject: [PATCH] =?UTF-8?q?2170=20:=20=EC=84=A0=EA=B8=8B=EA=B8=B0=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week5/BOJ2170/BOJ2170_V1.cpp | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/week5/BOJ2170/BOJ2170_V1.cpp diff --git a/src/week5/BOJ2170/BOJ2170_V1.cpp b/src/week5/BOJ2170/BOJ2170_V1.cpp new file mode 100644 index 0000000..cb225df --- /dev/null +++ b/src/week5/BOJ2170/BOJ2170_V1.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +int N; +vector> inp; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + cin >> N; + + for (int i=0; i> st >> ed; + inp.push_back({st,ed}); + } + + sort(inp.begin(), inp.end()); + + int ret=0; + int st=inp[0].first,ed=inp[0].second; + + for (int i=1; i ed) { + ret += (ed-st); + st = inp[i].first; + ed = inp[i].second; + } else { + if (ed < inp[i].second) ed = inp[i].second; + } + } + + ret += (ed-st); + + cout << ret << '\n'; + + return 0; +} \ No newline at end of file