Submission
Status:
[-SSSS][SSSSS][SSSSSSSSSS]
Subtask/Task Score:
{0/20}{0/30}{0/50}
Score: 0
User: vachirasawin
Problemset: ห้องสมุดเมือง 3M
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-12 22:30:09
// grader-chan
// c2_ds66_3m.cpp | c2_ds66_3m
#include <bits/stdc++.h>
using namespace std;
int n;
vector<pair<int, int>> books;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
while (n--) {
int xi, yi;
cin >> xi >> yi;
books.push_back({xi, yi});
}
sort(books.begin(), books.end());
long long total = books[0].second - books[0].first;
int currY = books[0].second;
for (int i = 1; i < books.size(); i++) {
int x = books[i].first;
int y = books[i].second;
if (x >= currY) {
total += y - x;
currY = y;
} else if (y > currY) {
total += y - currY;
currY = y;
}
}
cout << total / 2 - 1 << endl;
return 0;
}