QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#24602 | #2556. Yet Another Interval Graph Problem | yuyue | WA | 4ms | 5880kb | C++17 | 1.7kb | 2022-04-01 15:18:30 | 2022-04-30 06:16:35 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define SZ(x) ((int)x.size()-1)
#define ms(a,b) memset(a,b,sizeof a)
#define F(i,a,b) for (int i=(a);i<=(b);++i)
#define DF(i,a,b) for (int i=(a);i>=(b);--i)
//#define mp make_pair
//#define OO(x) fixed<<setprecision(x)
using namespace std;
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline int read(){
char ch=getchar(); int w=1,c=0;
for(;!isdigit(ch);ch=getchar()) if (ch=='-') w=-1;
for(;isdigit(ch);ch=getchar()) c=(c<<1)+(c<<3)+(ch^48);
return w*c;
}
const int M=5050;
int n,k,a[M],num[M][M],ct;
LL dp[M],val[M],L[M],R[M],t[M];
vector<int> v[M];
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n=read(); k=read();
F(i,1,n){
L[i]=read(); R[i]=read(); t[++ct]=L[i]; t[++ct]=R[i]; a[i]=read();
}
sort(t+1,t+ct+1);
int N=unique(t+1,t+ct+1)-t-1;
F(i,1,n){
L[i]=lower_bound(t+1,t+N+1,L[i])-t;
R[i]=lower_bound(t+1,t+N+1,R[i])-t;
F(j,L[i],R[i]-1) val[j]+=a[i];
v[L[i]].pb(i);
// cerr<<L[i]<<" "<<R[i]<<" interval\n";
}
dp[0]=0;
F(i,1,N){
dp[i]=1e18;
priority_queue<int> q;
LL co=0;
DF(j,i-1,0){
for (int id:v[j+1]) if (R[id]<=i){
q.push(-a[id]);
while (q.size()>k) co-=q.top(),q.pop();
}
// cerr<<i<<" -> "<<j<<" "<<co<<" jjjj\n";
dp[i]=min(dp[i],dp[j]+val[i]+co);//,cerr<<j<<" "<<i<<" "<<num[j+1][i]<<" oooooo\n";
}
// cerr<<val[i]<<" "<<dp[i]<<"\n";
}
cout<<dp[N]<<"\n";
return 0;
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3712kb
input:
5 2 1 4 1 3 6 2 5 8 5 7 10 2 9 12 1
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 3ms
memory: 3620kb
input:
5 1 2 6 5 4 6 2 8 8 5 1 3 4 6 8 7
output:
12
result:
ok single line: '12'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5756kb
input:
1 1 260947663 693934985 986106006
output:
0
result:
ok single line: '0'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
2 2 148610427 148610427 611594176 148610427 148610427 241979785
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
2 2 189944467 208945642 113891402 208945642 235053342 250664551
output:
0
result:
ok single line: '0'
Test #6:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
2 2 259102823 862504466 73871288 91533165 259102823 447104717
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3688kb
input:
2 2 634621570 811155007 87507743 299710238 563644023 98163867
output:
0
result:
ok single line: '0'
Test #8:
score: 0
Accepted
time: 4ms
memory: 3632kb
input:
13 5 385168347 385168347 99054846 385168347 385168347 350748474 385168347 385168347 354902398 385168347 385168347 585042031 385168347 385168347 292548257 385168347 385168347 440215041 385168347 385168347 672336022 385168347 385168347 47484008 385168347 385168347 169165503 385168347 385168347 7956210...
output:
1929854426
result:
ok single line: '1929854426'
Test #9:
score: 0
Accepted
time: 3ms
memory: 3640kb
input:
13 6 249108165 750799499 699592153 249108165 457151813 987869795 134537888 782870665 390805464 134537888 782870665 649518079 204359052 634307327 182450369 204359052 774773106 730624930 249108165 774773106 537210767 204359052 774773106 97138905 204359052 457151813 416638849 134537888 524514128 250590...
output:
1237015857
result:
ok single line: '1237015857'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3668kb
input:
13 7 465368572 465924358 199562084 608564649 997082675 730929009 674709819 678581286 182758027 836643137 882107460 644654785 486136406 758292265 676143876 201512809 479098771 863674394 47616205 381197381 378671320 394857231 595748338 113052048 212725647 465368572 82608327 196452515 409999283 8763323...
output:
1099952673
result:
ok single line: '1099952673'
Test #11:
score: 0
Accepted
time: 1ms
memory: 3664kb
input:
13 2 31872098 871680392 682839350 61764730 487476526 831566242 381374440 997221351 669699198 107368862 640403153 740367257 569214208 652115395 148284098 519532336 743844154 95873458 118903321 512516605 142755369 419658872 669010905 189660758 199540065 249254316 625038715 181930274 228478402 51457966...
output:
3609049933
result:
ok single line: '3609049933'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3836kb
input:
14 5 728352335 728352335 381359028 728352335 728352335 112308217 728352335 728352335 674696127 728352335 728352335 807714141 728352335 728352335 446795815 728352335 728352335 734255090 728352335 728352335 587451095 728352335 728352335 269358391 728352335 728352335 39475712 728352335 728352335 810785...
output:
2424971387
result:
ok single line: '2424971387'
Test #13:
score: 0
Accepted
time: 1ms
memory: 5836kb
input:
14 12 191793304 552864388 80949254 104805491 219644066 69701295 186898587 431239708 24064180 186898587 655934651 814445303 431239708 459349784 928677053 178946842 552864388 859560577 328428262 459349784 654624260 104805491 552864388 950062504 219644066 552864388 250581246 104805491 191793304 2348381...
output:
50607767
result:
ok single line: '50607767'
Test #14:
score: 0
Accepted
time: 3ms
memory: 5660kb
input:
14 14 300455461 658411147 118564055 74775444 249650757 803408069 664445103 893656382 599127386 249650757 281129734 530905142 58928870 615333424 353022736 642734658 660816046 173630646 4495104 715536786 916711506 170445688 656301801 252422382 292382181 656301801 895698233 74065627 479191864 293882251...
output:
0
result:
ok single line: '0'
Test #15:
score: 0
Accepted
time: 3ms
memory: 5792kb
input:
14 8 432046489 978881069 231142550 497322386 878782752 362048483 256198933 792937733 372555775 66506431 895129946 809601646 298840475 627033669 515057457 99457507 609186096 816771967 361334042 978881069 853460916 114590942 448110575 935917705 13145092 508015426 651654 90350442 227603751 34457268 292...
output:
1215869240
result:
ok single line: '1215869240'
Test #16:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
15 7 71536323 71536323 663663210 71536323 71536323 168835257 71536323 71536323 554298368 71536323 71536323 885162058 71536323 71536323 451300269 71536323 71536323 583584739 71536323 71536323 912631577 71536323 71536323 786200071 71536323 71536323 764561728 71536323 71536323 956470730 71536323 715363...
output:
2670135491
result:
ok single line: '2670135491'
Test #17:
score: 0
Accepted
time: 4ms
memory: 5536kb
input:
15 10 389002390 832393214 312563251 313520949 389002390 591724283 187656255 313520949 657322896 313520949 632787109 534662126 75456701 832063493 410062522 187656255 281053094 843272031 75456701 313520949 772037754 286247352 389002390 362794615 281053094 758595444 674458236 832393214 832393214 738615...
output:
921225063
result:
ok single line: '921225063'
Test #18:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
15 14 502982426 695256104 37566026 360811734 970630492 580919834 12460198 468757302 720529449 47607915 523380702 827220907 239024704 559272374 175125789 12460198 78664236 188619602 605867309 680213266 454751691 525329146 911823294 686760012 4261798 468757302 443946923 360811734 925969063 151623658 5...
output:
37566026
result:
ok single line: '37566026'
Test #19:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
15 8 98164859 808676227 779445750 128386421 716816201 597563428 234209607 784220068 485477760 40281846 145198031 878836035 30897339 313983968 176798112 37301494 462024528 537670476 249351686 446325020 709390656 797601962 856372121 536950461 110181370 781175898 376264592 254323552 576269929 849302167...
output:
1853900270
result:
ok single line: '1853900270'
Test #20:
score: 0
Accepted
time: 2ms
memory: 5780kb
input:
16 6 414720311 414720311 945967393 414720311 414720311 930395001 414720311 414720311 874092097 414720311 414720311 962609975 414720311 414720311 605547827 414720311 414720311 22848980 414720311 414720311 387555163 414720311 414720311 153298646 414720311 414720311 339904640 414720311 414720311 682119...
output:
4190876180
result:
ok single line: '4190876180'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3704kb
input:
16 3 8192334 296138897 693920352 296138897 940726987 968523078 298351952 298351952 585548907 298351952 298351952 404622054 298351952 940726987 596480694 8192334 46107911 972207678 46107911 102756404 184418543 73780914 164854509 70494022 46107911 298351952 508400633 594885466 940726987 58109036 81923...
output:
2562185596
result:
ok single line: '2562185596'
Test #22:
score: 0
Accepted
time: 3ms
memory: 5736kb
input:
16 12 275641614 801841335 811343806 95577059 866885529 63464303 394724161 626550634 987155703 429903353 880742943 123536672 85500274 511098550 997228841 416685349 663054530 763417069 728990898 729020007 992791877 17966150 626550634 826130345 728990898 811529667 697228317 191798932 882247362 41943047...
output:
690675139
result:
ok single line: '690675139'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
16 15 207378409 565152608 327748949 130338029 545690944 978302564 35248203 682729898 333558529 211875096 842599418 93294615 85063237 966649821 133506062 490343758 827886043 258568985 243659596 492931571 565320396 158053532 655699310 578174704 74296171 863518101 161942938 278000331 424880475 51892287...
output:
93294615
result:
ok single line: '93294615'
Test #24:
score: 0
Accepted
time: 1ms
memory: 3740kb
input:
15 8 311276485 886531075 542687345 303889791 886531075 231384714 320479222 886531075 468740692 721363813 886531075 77232377 228450314 886531075 827150033 527057547 886531075 116793316 311276485 886531075 785494700 273376721 886531075 232872222 311276485 886531075 275418603 724304477 886531075 514598...
output:
1486331062
result:
ok single line: '1486331062'
Test #25:
score: 0
Accepted
time: 3ms
memory: 3716kb
input:
15 2 741431866 959250144 688474833 826599694 959250144 589285705 3084690 652474523 131543181 3084690 818625976 252986613 667409877 959250144 294214085 741431866 959250144 333822660 789305564 959250144 307175183 652474523 959250144 178282282 689642919 959250144 640147543 3084690 826599694 393036587 9...
output:
3977226216
result:
ok single line: '3977226216'
Test #26:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
15 10 281053094 834779585 362794615 75456701 657322896 674458236 832063493 834779585 73861509 591724283 834779585 125024719 354953290 834779585 706013306 75456701 286247352 46980969 75456701 313520949 646003564 75456701 281053094 546712737 75456701 354953290 667713302 75456701 632787109 109150131 31...
output:
408707615
result:
ok single line: '408707615'
Test #27:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
15 4 141497923 548025160 785806426 141497923 527660509 720655899 141497923 771371793 828385845 141497923 843779781 99422560 141497923 352758161 38982198 141497923 155346807 243766753 141497923 828257135 241640981 141497923 921180816 402088000 141497923 353850883 834255872 141497923 826704874 6473136...
output:
3328733790
result:
ok single line: '3328733790'
Test #28:
score: 0
Accepted
time: 1ms
memory: 5880kb
input:
16 16 66022690 978150230 354759825 602783405 978150230 563217474 212301933 978150230 214922773 628180783 978150230 273946374 659163903 978150230 527604785 817565058 978150230 760025478 602783405 978150230 791570876 823067206 978150230 411882374 823067206 978150230 92521476 640571236 978150230 952104...
output:
0
result:
ok single line: '0'
Test #29:
score: 0
Accepted
time: 1ms
memory: 3768kb
input:
16 12 590274613 889380200 452952399 327794203 889380200 251229138 5330990 744933187 929170485 5330990 314614327 377216688 409453342 889380200 536747299 5330990 54904376 32440775 361401916 889380200 321742341 5330990 70074176 974876069 327794203 889380200 437471787 361401916 889380200 989756541 54904...
output:
756715795
result:
ok single line: '756715795'
Test #30:
score: 0
Accepted
time: 4ms
memory: 3688kb
input:
16 3 585548907 968523078 744856771 46107911 968523078 333993896 8192334 606692761 424145644 8192334 398644849 805825024 8192334 693920352 790872411 8192334 542551430 496441740 298351952 968523078 277150098 164854509 968523078 963199595 8192334 298351952 834534890 298351952 968523078 267503821 819233...
output:
6399014605
result:
ok single line: '6399014605'
Test #31:
score: 0
Accepted
time: 1ms
memory: 3692kb
input:
16 15 725916 57874638 27947927 725916 324502093 574757183 725916 248536551 239572123 725916 652533338 100510176 714583077 995185465 11406295 725916 372473799 491363244 725916 925611281 139579909 725916 248536551 858441046 725916 810672756 751074163 725916 129902704 747194470 725916 281408124 8552275...
output:
11406295
result:
ok single line: '11406295'
Test #32:
score: 0
Accepted
time: 3ms
memory: 3708kb
input:
14 1 623816097 623816097 68434400 623816097 623816097 725559682 623816097 623816097 678758318 623816097 623816097 368499632 623816097 623816097 495567409 623816097 623816097 236794280 623816097 623816097 779885584 623816097 623816097 879061467 623816097 623816097 537101862 623816097 623816097 465992...
output:
5864098008
result:
ok single line: '5864098008'
Test #33:
score: 0
Accepted
time: 4ms
memory: 3776kb
input:
14 1 474097486 930251201 788591065 2688701 471061191 845510022 2688701 203686122 275418775 203686122 601081080 31535815 474097486 474097486 228315825 161901890 474097486 85031827 203686122 601081080 337856340 471061191 601081080 604276423 161332531 471061191 357335089 262608550 474097486 82141704 26...
output:
3746923312
result:
ok single line: '3746923312'
Test #34:
score: -100
Wrong Answer
time: 0ms
memory: 3752kb
input:
14 1 494186620 531108277 961242307 620452125 623567580 364091773 23975216 357841107 512604788 59502148 793676488 729004547 293504000 748896401 598615542 398747973 967374174 642479347 31019655 476793418 584205112 376644841 543109385 320093318 874414082 884558783 925710684 327711462 354634260 92343656...
output:
5780071268
result:
wrong answer 1st lines differ - expected: '4831774383', found: '5780071268'