https://cses.fi/paste/3a725d319d3ccec42f13f4/
#include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector<pair<int,int>>vec; long long n,a,b,k=0,res=0; cin>>n; while(n--){ cin>>a>>b; vec.push_back({b,a}); } sort(vec.begin(),vec.end()); for(auto p:vec){ if(p.second>=k){ res++; k=p.first; } } cout<<res; return 0; }