标签:des style color io os ar for div art
Description
Input
Output
Sample Input
3 10 1 7 3 6 6 10
Sample Output
2
最小代价的区间覆盖。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<map>
using namespace std;
typedef long long LL;
const int maxn=25000+100;
struct node{
int st,ed;
}e[maxn];
int n,m;
int cmp(node l1,node l2)
{
if(l1.st==l2.st)
return l1.ed>l2.ed;
return l1.st<l2.st;
}
int main()
{
int ed,temp;
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++)
scanf("%d%d",&e[i].st,&e[i].ed);
sort(e,e+n,cmp);
if(e[0].st!=1)
{
printf("-1\n");
continue;
}
int ans=1;
ed=e[0].ed;
temp=0;
for(int i=1;i<n;i++)
{
if(e[i].st>ed+1)
{
ed=temp;
ans++;
}
if(e[i].st<=ed+1)
{
if(e[i].ed>temp)
temp=e[i].ed;
if(e[i].ed==m)
{
ans++;
ed=m;
break;
}
}
}
if(ed==m) printf("%d\n",ans);
else printf("-1\n");
}
return 0;
}标签:des style color io os ar for div art
原文地址:http://blog.csdn.net/u013582254/article/details/39371177