UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204132#3579. 干杯Duduuuu100128ms1984kbC++11842b2024-04-21 10:59:042024-04-21 12:11:07

answer

/*
	Name: NOI.AC-cheers
	Author: Duduuuu
	Date: 21/04/24
	Description: 
*/
#include<bits/stdc++.h>
using namespace std;
int n,t;
struct camera{
	int l,r;
}c[100001];
bool cmp(camera a,camera b){
	if(a.l==b.l){
		return a.r>b.r;
	}else{
		return a.l<b.l;
	}
}
int solve(){
	if(c[1].l>0){
		return -1;
	}
	int ans=1;
	int nowfar =c[1].r;
	int maxright=c[1].r;
	if(nowfar>=t){
		return ans;
	}
	int i=2;
	while(true){
		for(;(i<=n&&c[i].l<=nowfar);i++){
			maxright=max(maxright,c[i].r);
		}
		if(maxright<=nowfar){
			return -1;
		}
		ans++;
		nowfar=maxright;
		if(nowfar>=t){
			return ans;
		}
	}
	return -1;
}
int main(){
	int tp;
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&c[i].l,&c[i].r);
	}
	sort(c+1,c+n+1,cmp);
	tp = solve();
	printf("%d",tp);
	return 0;
}
	

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

20 2270
925 1447
1070 1518
1083 1405
1410 1667
665 1215
1571 2033
1598 1804
1108 1366
129 304
1706 2...

output:

8

result:

ok single line: '8'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1204kb

input:

20 2276
908 1382
1339 1768
707 849
1375 1938
1723 1850
20 338
464 702
860 1232
0 559
0 46
2052 2276
...

output:

6

result:

ok single line: '6'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

20 2178
903 1134
568 759
1081 1429
164 412
1721 2105
1270 1444
1460 1751
1381 1956
9 207
0 13
1564 1...

output:

9

result:

ok single line: '9'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1212kb

input:

1000 485762048
461595533 462438047
183219253 183935922
403233160 404691571
226789663 228183630
29135...

output:

345

result:

ok single line: '345'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1208kb

input:

1000 496220301
201725070 202828242
273891548 275095507
93003342 93937955
283468580 284362106
3325495...

output:

347

result:

ok single line: '347'

Test #6:

score: 10
Accepted
time: 22ms
memory: 1980kb

input:

100000 500789093
0 9383
3315 18814
5677 28044
6437 37328
34140 40305
39276 45309
42741 53963
43707 5...

output:

65475

result:

ok single line: '65475'

Test #7:

score: 10
Accepted
time: 21ms
memory: 1984kb

input:

100000 499931317
0 4500
392 10390
7746 19150
13140 24778
17916 26270
25462 27623
27509 29960
29306 3...

output:

65542

result:

ok single line: '65542'

Test #8:

score: 10
Accepted
time: 30ms
memory: 1980kb

input:

100000 499615802
113775516 113790359
483207940 483210635
437168973 437186748
347793569 347805407
423...

output:

34320

result:

ok single line: '34320'

Test #9:

score: 10
Accepted
time: 24ms
memory: 1984kb

input:

100000 499500287
430592816 430617353
387768808 387787047
349038111 349045020
192309780 192328839
473...

output:

34462

result:

ok single line: '34462'

Test #10:

score: 10
Accepted
time: 31ms
memory: 1980kb

input:

100000 498803629
483229798 483242533
205372464 205380752
220073152 220085677
444497307 444507301
461...

output:

34298

result:

ok single line: '34298'