E - Third-Party Software - 2 Gym - 102215E (贪心)

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=200010;
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=1;i<=n;i++){
        cin>>q[i].l>>q[i].r;
        q[i].id=i;
    }
    sort(q+1,q+1+n,cmp);
    if(q[1].l!=1)return cout<<"NO"<<endl,0;
    int now=q[1].r;
    ans.push_back(q[1].id);//首先将第一条放进去
    for(int i=2;i<=n;){
        if(q[i].l>now+1)return cout<<"NO"<<endl,0;
        else{
            int temp=now,pos=q[i].id;
            while(i<=n&&q[i].l<=now+1){//在当前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,0;
    cout<<"YES"<<endl;
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;
}


原文地址:https://www.cnblogs.com/cherish-lin/p/11107926.html

时间: 2024-11-02 00:33:44

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

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

题目链接: Gym Class Time Limit: 6000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description 众所周知,度度熊喜欢各类体育活动. 今天,它终于当上了梦寐以求的体育课老师.第一次课上,它发现一个有趣的事情.在上课之前,所有同学要排成一列, 假设最开始每个人有一个唯一的ID,从1到N,在排好队之后,每个同学会找出包括自己在内的前方所有同学的最小ID,作为

hdu 5695 Gym Class 贪心+拓扑

题目链接:hdu 5695 Gym Class 题目意思:每个同学会找出包括自己在内的前方所有同学的最小ID,作为自己评价这堂课的分,最后的排队结果可以使得所有同学的评价分数和最大 思路:贪心的策略是尽量把id大的放在前面,拓扑排序是为了挑出没有排队限制的且数目尽可能大的id放在前面 /************************************************************** Problem:hdu 5695 User: youmi Language: C++

UVaLive 6588 &amp;&amp; Gym 100299I (贪心+构造)

题意:给定一个序列,让你经过不超过9的6次方次操作,变成一个有序的,操作只有在一个连续区间,交换前一半和后一半. 析:这是一个构造题,我们可以对第 i 个位置找 i 在哪,假设 i  在pos 位置,那么如果 (pos-i)*2+i-1 <= n,那么可以操作一次换过来, 如果不行再换一种,如果他们之间元素是偶数,那么交换 i - pos,如果是奇数,交换 i - pos+1,然后再经过一次就可以换到指定位置. 代码如下: #pragma comment(linker, "/STACK:1

2016-5-21 letwetell Round3 (百度之星初赛,dfs序)

halfapri(- o -)Y { 1.2016百度之星Round2A 题目链接 题解链接 1001 All X 循环节 1002 Sitting in Line 状压dp 1003 Snacks 1004 D Game 1005 BD String 找规律 1006 Gym Class 贪心+topo 2.2012多校第7场 hdu4366 Successor 线段树 + dfs序 }

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

F. Doomsday Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/F Description Doomsday comes in t units of time. In anticipation of such a significant event n people prepared m vaults in which, as they think, it will

Gym - 100338E Numbers 贪心

Gym - 100338E 题意:给你n,k问在1-n中能整出k的字典序最小的数.范围1018 思路:比较简单的贪心了,枚举10的幂m,然后加上k-m%k, 更新答案就可以了,数据一定要用unsigned long long,我就在这里挂了几次,查了半天. 1 #include <iostream> 2 #include <cstdio> 3 #include <fstream> 4 #include <algorithm> 5 #include <c

Codeforces Gym 101174 A Within Arm&#39;s Reach 贪心 手臂

#include<iostream> #include<stdio.h> #include <string.h> #include <algorithm> #include <vector> #include <math.h> using namespace std; #define LL long long const int maxn=25; double a[maxn],l[maxn],r[maxn]; double ex,ey

GYM 101173 F.Free Figurines(贪心||并查集)

原题链接 题意:俄罗斯套娃,给出一个初始状态和终止状态,问至少需要多少步操作才能实现状态转化 贪心做法如果完全拆掉再重装,答案是p[i]和q[i]中不为0的值的个数.现在要求寻找最小步数,显然要减去一些多余的步数.如果初始的一些链的前端是终止的某一条链的连续的一部分,那么这条链就不用被拆开再连上,这样每一个长度为x的链对答案的贡献就是-2*(x-1),对每条链进行同样的操作之后就是答案 #include <iostream> #include<cstdio> #include<

Gym 100886J Sockets 二分答案 + 贪心

Description standard input/outputStatements Valera has only one electrical socket in his flat. He also has m devices which require electricity to work. He's got n plug multipliers to plug the devices, the i-th plug multiplier has ai sockets. A device