structLine{ int left, right; }; booloperator<(Line a, Line b) { if (a.left != b.left) return a.left < b.left; return a.right < b.right; } int n, ans; Line v[1000010];
intmain(){ scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &v[i].left, &v[i].right); } sort(v, v+n); ans = 0; int border = 0; for (int i = 0; i < n; ++i) { if (v[i].left >= border) { ans++; border = v[i].right; } else { border = min(border, v[i].right); } } printf("%d\n", ans); return0; }
structLine{ int left, right; }; booloperator<(Line a, Line b) { if (a.right != b.right) return a.right < b.right; return a.left < b.left; } int n, ans; Line v[1000010];
intmain(){ scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d%d", &v[i].left, &v[i].right); } sort(v, v+n); ans = 0; int border = -1; for (int i = 0; i < n; ++i) { if (border <= v[i].left) { ans++; border = v[i].right; } } printf("%d\n", ans); return0; }
intmain(){ scanf("%d", &n); for (int i = 0; i < n; ++i) { scanf("%d", v+i); } ans = v[0]; for (int i = 1; i < n; ++i) { if (v[i]>v[i-1]) { ans += v[i] - v[i-1]; } } cout << ans << endl; return0; }