Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- struct Pair {
- int l, r;
- } a[100500];
- bool cmp(Pair p1, Pair p2) {
- return p1.r < p2.r;
- }
- int main() {
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> a[i].l >> a[i].r;
- sort(a + 1, a + n + 1, cmp);
- int last = 0, ans = 0;
- for (int i = 1; i <= n; i++) {
- if (a[i].l > last)
- ans++, last = a[i].r;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement