一绿二红三深蓝
查看原帖
一绿二红三深蓝
355424
Lish_Xizse楼主2021/10/10 21:34

Rt

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct Node{
    int x,y;
}a[25010];
bool cmp(Node p1,Node p2){
    return p1.y<p2.y;
}
int main(){
    int n,t;
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i].x,&a[i].y);
    }
    bool flag[1000010]={0};
    for(int i=1;i<=n;i++){
        for(int j=a[i].x;j<=a[i].y;j++){
            flag[j]=1;
        }
    }
    for(int i=1;i<=t;i++){
        if(flag[i]!=1){
            printf("-1");
            return 0;
        }
    }
    int ans=0;
    sort(a,a+n,cmp);
    int pos=0,now=0;
    while(pos<n){
        if(a[pos].x>=now){
            now=a[pos].y;
            ans++;
        }
        pos++;
    }
    printf("%d",ans);
    return 0;
}
2021/10/10 21:34
加载中...