diff --git "a/JinHyeok/202507/22 \354\204\240\352\270\213\352\270\260.md" "b/JinHyeok/202507/22 \354\204\240\352\270\213\352\270\260.md" new file mode 100644 index 0000000..535f7a6 --- /dev/null +++ "b/JinHyeok/202507/22 \354\204\240\352\270\213\352\270\260.md" @@ -0,0 +1,46 @@ +``` +#include +#include +#include + +using namespace std; + +int main() { + ios::sync_with_stdio(false); + cin.tie(nullptr); + + int N; + cin >> N; + + vector> lines(N); + for (int i = 0; i < N; i++) { + cin >> lines[i].first >> lines[i].second; + } + + sort(lines.begin(), lines.end()); + + long long totalLength = 0; + int currentStart = lines[0].first; + int currentEnd = lines[0].second; + + for (int i = 1; i < N; i++) { + int nextStart = lines[i].first; + int nextEnd = lines[i].second; + + if (nextStart <= currentEnd) { + currentEnd = max(currentEnd, nextEnd); + } else { + totalLength += (long long)(currentEnd - currentStart); + currentStart = nextStart; + currentEnd = nextEnd; + } + } + + totalLength += (long long)(currentEnd - currentStart); + + cout << totalLength << '\n'; + + return 0; +} + +```