mohanzhe @ 2024-11-03 09:25:07
#include<bits/stdc++.h>
using namespace std;
struct node{
int l,r;
}a[3000000];
bool cmp(node a,node b)
{
if(a.l<b.l) return 1;
if(a.l>b.l) return 0;
return a.r<b.r;
}
int n,t,ans,num=1;
int main()
{
cin>>n>>t;
for(int i=1;i<=n;i++)
scanf("%d%d",&a[i].l,&a[i].r);
int i=1;
while(i<=t){
if(num>n||a[num].l>i){
cout<<"-1"<<endl;
return 0;
}
while(a[num+1].l<=i){
if(num==n-1||num==n){
num=n;
break;
}
num++;
}
i=a[num].r+1;
num++;
ans++;
}
cout<<ans<<endl;
return 0;
}
by Error303 @ 2024-11-03 09:34:24
qp
by mohanzhe @ 2024-11-03 09:37:37
P2684