熊恒锐 • 22天前
using namespace std;
struct node {
int x, y;
} p[100005];
bool cmp(node c, node d) {
return c.y < d.y;
}
int main() {
int n, len = -2147483647;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].x >> p[i].y;
}
sort(p + 1, p + 1 + n);
int ans = 0;
for (int i = 1; i <= n; i++) {
if (p[i].y > len) {
ans += p[i].y - max(p[i].x, len) + 1;
len = p[i].y + 1;
}
}
cout << ans;
return 0;
}
评论:
请先登录,才能进行评论