AcWing 803. 区间合并
原题链接
简单
作者:
术
,
2021-01-03 20:58:18
,
所有人可见
,
阅读 337
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
const int N=100005;
int l,r;
int n;
int res;
vector<PII> a;
int main()
{
cin>>n;
while(n--)
{
cin>>l>>r;
a.push_back(make_pair(l,r));
}
sort(a.begin(),a.end());
int st=-2e9,ed=-2e9;
cout<<st<<endl;
for(int i=0; i<a.size(); i++)
{
if(a[i].first>ed)
{
//if(ed!=-2e9)
res++;
st=a[i].first;
ed=a[i].second;
}
else
ed=max(ed,a[i].second);
}
cout<<res;
//cout << "Hello world!" << endl;
return 0;
}