# C. Third-Party Software

C. Third-Party Software
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Pavel is developing a game. To do that, he needs functions available in a third-party library too famous to be called. It is known that the functionifirst appeared in versionaiand existed until versionbi, and starting from the versionbi+ 1, it is absent in this library.

The library is not free and Pavel needs all the functions. Which minimal number of versions he need to purchase to be able to use all the functions?

Input

The first line contains a single integern(1 ≤n≤ 200000) — the number of the functions.

Each of the nextnlines contains two integersaiandbi(1 ≤aibi≤ 109) — the interval of library versions where functioniwas available.

Output

In the first line output a single integerk— the minimal number of library versions need to be purchased to unlock all functions.

In the second line outputkdistinct integers — the numbers of versions need to be purchased.

If there are several possible answers, output any of them.

Example
input
Copy
5
2 4
1 3
2 3
3 6
4 5

output
Copy
2
3 4


#### 题解： 结构体排序     我们可以画一条水平数轴，把版本范围区间画出来，版本有（重叠）交叉范围的，为了少买游戏版本，就缩小区间。最后判断有多少个不想交的区间，表示必买的游戏版本，存入数组里面。

#include<bits/stdc++.h>
using namespace std;
const int N=200000;
int s[N];
struct node
{
int s,y;
} q[N];
bool cmp(node a,node b)
{
if(a.s==b.s)
return a.y<b.y;
return a.s<b.s;
}
int main()
{
int a,b,n,minn,maxn,cnt=0;
cin>>n;
for(int i=0; i<n; i++)
cin>>q[i].s>>q[i].y;
stable_sort(q,q+n,cmp);
minn=q[0].s,maxn=q[0].y;
for(int i=1; i<n; i++)
{
if(q[i].s>maxn)
{
s[cnt++]=minn;
minn=q[i].s;
maxn=q[i].y;
}
minn=max(minn,q[i].s),maxn=min(maxn,q[i].y);///压缩小集合
}
s[cnt++]=minn;
cout<<cnt<<endl;
for(int i=0; i<cnt; i++)
cout<<s[i]<<" ";
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120