72pts贪心求助
查看原帖
72pts贪心求助
169594
Heart_Of_Iron_4楼主2023/10/6 16:57

rt

#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define FOR(qw,we,er) for(int qw=we;qw<=er;++qw)
int n,t,t1,t2,t3,ans;
struct xy
{
	int x,y;
}a[25000];
struct cmp
{
	bool operator ()(xy qwer,xy wert)
	{
		return qwer.x<wert.x;
	}
};
signed main()
{
	scanf("%lld%lld",&n,&t);
	FOR(i,1,n)
	{
		scanf("%lld%lld",&a[i].x,&a[i].y);
	}
	sort(a+1,a+1+n,cmp());
	t1=1;
	FOR(i,1,t)
	{
		if(a[t1].x>i)
		{
			printf("-1\n");
			exit(0);
		}
		t2=0;
		while(a[t1].x<=i&&t1<=n)t2=max(t2,a[t1++].y);
		if(t2<t1)
		{
			printf("-1\n");
			exit(0);
		}
		ans++;
		i=t2+1;
		//printf("%lld %lld\n",t1,t2);
	}
	printf("%lld\n",ans);
	return 0;
}
2023/10/6 16:57
加载中...