Pavel is developing another game. To do that, he again needs functions available in a third-party library too famous to be called. There are mm functions numbered from 11to mm, and it is known that the ii-th version of the library contains functions from aiai to bibi inclusively.

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

Input

The first line contains two integers nn and mm (1≤n≤200000,1≤m≤1091≤n≤200000,1≤m≤109) — the number of library versions and the number of functions.

Each of the next nn lines contains two integers aiai and bibi (1≤ai≤bi≤m1≤ai≤bi≤m) — the interval of function numbers available in the ii-th version.

Output

In the first line output «YES» or «NO», depending on if it's possible or not to purchase library versions to use all the functions.

In case of the positive answer output two more lines. In the second line output a single integer kk — the minimal number of library versions needed to be purchased. In the third line output kk distinct integers — the numbers of versions needed to be purchased.

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

Examples

Input
4 8
1 2
3 4
5 6
7 8
Output
YES
4
1 2 3 4
Input
4 8
1 5
2 7
3 4
6 8
Output
YES
2
1 4
Input
3 8
1 3
4 5
6 7
Output
NO
题解:首先按照左端点从小到大排序,左端点相同按照右端点从大到小排序。然后贪心选取,将设当前能到达的最远点为now,我们需要在左端点<=now+1的线段中选取右端点最大的放进去,之后更新now。
其他不满足的情况特判即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=;
struct node
{
int l,r,id;
}q[maxn];
int cmp(node a,node b)//按左端点从小到大,右端点从大到小排序
{
if(a.l==b.l)return a.r>b.r;
return a.l<b.l;
}
vector<int>ans;
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++){
cin>>q[i].l>>q[i].r;
q[i].id=i;
}
sort(q+,q++n,cmp);
if(q[].l!=)return cout<<"NO"<<endl,;
int now=q[].r;
ans.push_back(q[].id);//首先将第一条放进去
for(int i=;i<=n;){
if(q[i].l>now+)return cout<<"NO"<<endl,;
else{
int temp=now,pos=q[i].id;
while(i<=n&&q[i].l<=now+){//在当前now可连接的取右端点最大值
if(q[i].r>temp){
temp=q[i].r;
pos=q[i].id;
}
i++;
}
if(now==temp)continue;//防止不必要的放入
now=temp;
ans.push_back(pos);
}
}
if(now<m)return cout<<"NO"<<endl,;
cout<<"YES"<<endl;
cout<<ans.size()<<endl;
for(int i=;i<ans.size();i++){
cout<<ans[i]<<" ";
}
cout<<endl;
return ;
}

E - Third-Party Software - 2 Gym - 102215E (贪心)的更多相关文章

  1. hdu-5695 Gym Class(贪心+拓扑排序)

    题目链接: Gym Class Time Limit: 6000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  2. HDU 5965 Gym Class 贪心+toposort

    分析:就是给一些拓补关系,然后求最大分数,所以贪心,大的越靠前越好,小的越靠后越好 剩下的就是toposort,当然由于贪心,所以使用优先队列 #include <iostream> #i ...

  3. Ice Cream Tower Gym - 101194D (贪心 + 二分 )

    题目链接 : https://cn.vjudge.net/problem/Gym-101194D 题目大意 : 给你n个冰激凌球,让你用这些冰激凌球去垒冰激凌,要求是下面的这一个必须是他上面一个的两倍 ...

  4. Pond Cascade Gym - 101670B 贪心+数学

    题目:题目链接 思路:题目让求最下面池子满的时间和所有池子满的时间,首先我们考虑所有池子满的时间,我们从上到下考虑,因为某些池子满了之后溢出只能往下溢水,考虑当前池子如果注满时间最长,那么从第一个池子 ...

  5. UVaLive 6588 && Gym 100299I (贪心+构造)

    题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i  在pos 位置, ...

  6. 贪心 Gym 100502E Opening Ceremony

    题目传送门 /* 题意:有一堆砖块,每一次操作可以选择消去任意一行,也可以选择消去任意一列.求要消去所有的砖块需要最小的操作数 贪心:首先清楚的是消去最高列的最佳,消去第一行最佳,行列的顺序只对中间过 ...

  7. Codeforces Gym 100803C Shopping 贪心

    Shopping 题目连接: http://codeforces.com/gym/100803/attachments Description Your friend will enjoy shopp ...

  8. Codeforces Gym 100231B Intervals 线段树+二分+贪心

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...

  9. codeforces Gym 100187F F - Doomsday 区间覆盖贪心

    F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F ...

随机推荐

  1. c/c++ 获取BMP文件信息

    #include <stdio.h> #include <string.h> typedef struct BITMAPFILEHEADER { // BMP文件头 u_int ...

  2. 使用Zabbix监控Nginx服务实战案例

    使用Zabbix监控Nginx服务实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.  一.编译安装nginx步骤详解并开启状态页 博主推荐阅读: https://www.cn ...

  3. P1074 宇宙无敌加法器

    P1074 宇宙无敌加法器 转跳点:

  4. imple-unpack---攻防世界

    拿到题目查壳没有发现.题目已经明确说了,基本上是有壳的,Linux下面看看 应该就是upx的壳了,下载upx进行脱壳,https://sourceforge.net/projects/upx/file ...

  5. 使用Spring Data JPA的Spring Boot

    本文教你开始使用Spring Data JPA.来自优锐课JAVA架构专业讲师精心整理. 欢迎使用带有Spring Data JPA的Spring Boot教程!在本教程中,我们将看到Spring D ...

  6. login SMTP send mail error : Unable to read data from the transport connection: net_io_connectionclosed

    client.Credentials = new NetworkCredential(sSMTPuser, sSMTPpass); client.Credentials = new NetworkCr ...

  7. 在 Delphi 中使用微软全文翻译的小例子

    使用帮助 需要先去申请一个 AppID: http://www.bing.com/toolbox/bingdeveloper/使用帮助在: http://msdn.microsoft.com/en-u ...

  8. MongoDB_04_插入和查询

    案列需求: 存在文章评论的数据存放到MongoDB中,数据结构参考如下: 数据库:articledb 专栏文章评论 comment / / 字段名称 字段含义 字段类型 备注 _id ID Objec ...

  9. 剑指offer自学系列(四)

    题目描述: 输入一个正整数数组,把数组里面所有数字拼接起来排成一个数,打印能拼接出的所有数字中最小的一个,例如输入数组{3,32,321},输出的最小数字为321323 题目分析: 如果采用穷举法,把 ...

  10. POJ3295 Tautology重言式

    Tautology 思路很简单,对于p.q.r.s.t暴力枚举是0还是1,判断即可.判断时像写表达式求值那样用栈.为了方便可以从后往前,因为最后一个肯定不是运算.那几个奇奇怪怪的函数可以找规律然后转为 ...