AcWing 906. 区间分组
原题链接
简单
作者:
I+III
,
2021-06-03 09:41:19
,
所有人可见
,
阅读 191
#include<bits/stdc++.h>
using namespace std;
const int N = 100000;
typedef pair<int, int> PII;
PII p[N];
int main(){
int n;
cin>>n;
for(int i = 0; i < n; i++) cin>>p[i].first>>p[i].second;
sort(p, p + n);
priority_queue <int, vector<int>, greater<int>> q;
for(int i = 0; i < n; i++){
int l = p[i].first, r = p[i].second;
if(q.empty() || l < q.top()){
q.push(r);
}
else if(q.top() <= l){
q.pop();
q.push( r);
}
}
cout<<q.size()<<endl;
return 0;
}