C - Third-Party Software Gym - 101755C (贪心)

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 function i first appeared in version ai and existed until version bi, and starting from the version bi + 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 integer n (1 ≤ n ≤ 200000) — the number of the functions.

Each of the next n lines contains two integers ai and bi (1 ≤ ai ≤ bi ≤ 109) — the interval of library versions where function i was available.

Output

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

In the second line output k distinct integers — the numbers of versions need to be purchased.

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

Example

Input

5
2 4
1 3
2 3
3 6
4 5

Output

2
3 4

//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/

using namespace std;

struct node
{
    long long int x,y;
};

node n[200010];

int cmp(node a,node b){
   if(a.x==b.x){
    return a.y<b.y;
   }
   return a.x<b.x;
}

int main()
{
   long long int a,k=0;
   long long int m[200010];
   cin >> a;
   for(int i=1;i<=a;i++){
    cin >> n[i].x >> n[i].y;
   }
   if(a==1){
        cout << a << endl;
    cout << n[1].x;
   }
   else{
   sort(n+1,n+a+1,cmp);
   for(int i=1;i<a;i++){
    n[i].x=max(n[i+1].x,n[i].x);
    n[i].y=min(n[i+1].y,n[i].y);
    if(n[i].x>n[i].y){
        m[++k]=n[i].y;
      if(i==a-1){
        m[++k]=n[i+1].x;
     }
    }
    else{
        n[i+1].x=n[i].x;
        n[i+1].y=n[i].y;
         if(i==a-1){
        m[++k]=n[i+1].x;
     }
    }
   }
   cout << k << endl;
   for(int i=1;i<=k;i++){
    if(i==k){
        cout << m[i];
    }
    else{
        cout << m[i] << " ";
    }
   }}
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值