#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool compare(pair<int,int> a,pair<int,int> b){
if (a.second != b.second)
return a.second < b.second;
return a.first < b.first;
}
int main() {
int n;
cin >> n;
int cnt = 1;
vector<pair<int,int>> v(n);
for (int i = 0;i < n;i++) {
cin >> v[i].first >> v[i].second;
}
sort(v.begin(),v.end(),compare);
int end_time = v[0].second;
for (int i = 1;i < n;i++) {
if (v[i].first < end_time) {
continue;
}
if (v[i].first >= end_time) {
cnt++;
end_time = v[i].second;
}
}
cout << cnt;
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: