QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#43508#1495. Lifeguardsfeecle6418100 ✓446ms46220kbC++17626b2022-08-09 16:52:432022-08-09 16:52:45

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-08-09 16:52:45]
  • 评测
  • 测评结果:100
  • 用时:446ms
  • 内存:46220kb
  • [2022-08-09 16:52:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct Seg{
	int l,r;
	bool operator <(const Seg s) const {
		return l!=s.l?l<s.l:r>s.r;
	}
}a[100005],b[100005];
int n,N,m,f[100005][105],ans=0;
int main(){
	cin>>N>>m;
	for(int i=1;i<=N;i++)cin>>b[i].l>>b[i].r;
	sort(b+1,b+N+1);
	for(int i=1,cur=-1;i<=N;i++)if(cur<b[i].r)cur=b[i].r,a[++n]=b[i];else m=max(m-1,0);
	memset(f,0xc0,sizeof(f)),f[0][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=m;j++){
			for(int k=i-1;k>=0&&k>=i-j-1;k--)f[i][j]=max(f[i][j],f[k][j-(i-k-1)]+a[i].r-max(a[i].l,a[k].r));
		}
		ans=max(ans,f[i][max(0,m-(n-i))]);
	}
	cout<<ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 13ms
memory: 46184kb

input:

3 2
1 8
7 15
2 14

output:

12

result:

ok single line: '12'

Test #2:

score: 10
Accepted
time: 8ms
memory: 45816kb

input:

472 55
6077888 6090064
4871999 4878615
6946038 6955143
4328881 4337634
1931352 1940408
454117 462732
6296524 6307990
7212884 7222635
6199142 6211836
2544278 2551731
5138514 5144975
768019 777521
3349408 3360238
6502417 6515212
2671322 2679911
5679621 5689974
5064564 5076236
3342118 3352147
1387927 1...

output:

3700813

result:

ok single line: '3700813'

Test #3:

score: 10
Accepted
time: 27ms
memory: 45780kb

input:

4882 96
62535412 62542106
36668995 36676588
60378848 60389260
30255170 30265084
40053562 40062645
10822894 10831850
40682754 40691305
49193176 49200764
59666953 59677300
52101687 52111039
4752389 4760050
44845301 44852519
9975521 9983341
24546990 24552977
24390074 24399791
28729785 28735574
40731708...

output:

39948523

result:

ok single line: '39948523'

Test #4:

score: 10
Accepted
time: 240ms
memory: 45404kb

input:

50000 99
3443253 3444269
19799569 19800312
29048793 29049509
18895919 18896575
4162605 4163386
667095 668398
32700218 32701186
14340528 14341243
29758397 29759020
35017650 35018705
11398332 11399287
17166070 17166873
21725927 21726946
24253559 24254394
23711013 23711855
7156994 7158074
10624169 1062...

output:

37434346

result:

ok single line: '37434346'

Test #5:

score: 10
Accepted
time: 174ms
memory: 45444kb

input:

49785 82
27415369 27416397
21836194 21837490
26624191 26625262
36940507 36941408
19852564 19853310
31137285 31138343
22022992 22023887
50267822 50268790
34419182 34420086
231738 232630
11043268 11044061
41792530 41793349
39156666 39157524
45696387 45697645
57959783 57960633
68210455 68211426
4555506...

output:

41007479

result:

ok single line: '41007479'

Test #6:

score: 10
Accepted
time: 318ms
memory: 45820kb

input:

70000 98
4980448 4981537
45562845 45563749
4158845 4159702
43021974 43023083
21732970 21733657
48321143 48322537
7721899 7723060
14647548 14648843
20009619 20010569
48379190 48379880
9468982 9469778
37597526 37598243
43554589 43555522
8085136 8085922
13274471 13275640
40237288 40238250
38888652 3888...

output:

52435734

result:

ok single line: '52435734'

Test #7:

score: 10
Accepted
time: 446ms
memory: 46220kb

input:

100000 95
31394575 31395303
35035434 35036166
64896609 64897277
10992021 10992677
17899328 17900254
21235049 21236085
21825260 21826397
72355491 72356628
51097934 51098793
43022528 43023255
18626033 18626949
48380368 48381142
36901660 36902699
53823523 53824143
57181044 57181912
37079551 37080686
20...

output:

74878135

result:

ok single line: '74878135'

Test #8:

score: 10
Accepted
time: 274ms
memory: 46220kb

input:

100000 83
233039267 233039367
916657359 916657459
864715109 864715209
936842396 936842496
562959930 562960030
730029506 730029606
232012643 232012743
684125439 684125539
74354656 74354756
969280947 969281047
616579106 616579206
10886963 10887063
146442201 146442301
936755868 936755968
241861614 2418...

output:

9880370

result:

ok single line: '9880370'

Test #9:

score: 10
Accepted
time: 347ms
memory: 46092kb

input:

100000 90
816642137 816642237
185449925 185450025
619425312 619425412
335954840 335954940
14523568 14523668
522597020 522597120
755982712 755982812
749835334 749835434
16269569 16269669
577427902 577428002
378757393 378757493
290013689 290013789
299170714 299170814
598078466 598078566
85965624 85965...

output:

9879012

result:

ok single line: '9879012'

Test #10:

score: 10
Accepted
time: 330ms
memory: 46160kb

input:

100000 85
932471751 932471851
591128329 591128429
632579047 632579147
902529780 902529880
377540930 377541030
406044684 406044784
895898124 895898224
11965789 11965889
206361200 206361300
33540488 33540588
150614655 150614755
713801692 713801792
169829160 169829260
814073789 814073889
335070678 3350...

output:

9876663

result:

ok single line: '9876663'