有一条长度为 L 的马路需要打扫。
有 N 个打扫工人,第 i 个工人打扫 [Si,Ti] 范围内的马路。(马路从 1 到 L)
最少用多少个工人能把马路打扫干净,无解输出 −1。
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=25010;
struct Sweeper { int s,t; }a[N];
bool cmp(Sweeper a,Sweeper b) { return (a.s==b.s?a.t>b.t:a.s<b.s); }
int main() {
int n,l; scanf("%d %d",&n,&l);
for(int i=1;i<=n;i++) scanf("%d %d",&a[i].s,&a[i].t);
sort(a+1,a+n+1,cmp);
if(a[1].s>1) return printf("-1"),0;
int cur=1,cnt=1;
while(true) {
int tmp=cur;
while(a[cur].t<=a[tmp].t&&cur<=n) cur++;
if(cur>n) return printf("-1"),0;
cnt++;
if(a[cur].t==l) return printf("%d",cnt),0;
}
printf("-1");
return 0;
}
样例:
1 7
3 6
6 10
------
2