Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<utility>
- #include<algorithm>
- using namespace std;
- int main()
- {
- int total=1;
- int N,i,j;
- cin >> N;
- pair<long int,long int> pi[N];
- for(i=0;i<N;i++)
- {
- cin >> pi[i].first >> pi[i].second;
- }
- sort(pi,pi+N);
- int x=0;
- int y=1;
- while(x<N-1)
- {
- while(y<N)
- {
- if(pi[x].second<pi[y].first)
- {
- x=y;
- y=y+1;
- total=total+1;
- }
- else if (pi[x].second>=pi[y].first && pi[x].second>pi[y].second)
- {
- x=y;
- y=y+1;
- }
- else
- y=y+1;
- }
- x=x+1;
- }
- cout<<total<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement