QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#309178 | #1208. Keys | LYT0122 | 100 ✓ | 8ms | 14248kb | C++14 | 2.2kb | 2024-01-20 15:23:41 | 2024-01-20 15:23:42 |
Judging History
answer
#include <iostream>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int ll;
const int N=1e6+9,INF=1e9;
const double eps=1e-5;
typedef pair <int,int> PII;
inline int read()
{
int x=0,f=1;char c=getchar();
while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
return x*f;
}
inline ll readll()
{
ll x=0,f=1;char c=getchar();
while(c<'0' || c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0' && c<='9') {x=x*10+c-48,c=getchar();}
return x*f;
}
struct node{
int opt,v,id;
} p[N];
int n,m,K,cnt,a[N],b[N],nxt[N];
ll ans,f[2][N][2];
bool cmpp(node x,node y)
{
return x.v<y.v;
}
int main()
{
// #define FILEIO
#ifdef FILEIO
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
n=read(),m=read(),K=read();
for(int i=1;i<=n;i++) p[++cnt]={0,read(),i},p[++cnt]={1,read(),i};
sort(p+1,p+cnt+1,cmpp);
ans=p[1].v+m-p[cnt].v;
for(int i=1;i<cnt;i++)
{
int x=p[i+1].v-p[i].v;
if(p[i].opt==0 && p[i+1].opt==0) a[p[i].id]+=x;
else if(p[i].opt==1 && p[i+1].opt==1) a[p[i+1].id]+=x;
else if(p[i].opt==1 && p[i+1].opt==0) ans+=x;
else
{
if(p[i].id==p[i+1].id) a[p[i].id]+=x;
else nxt[p[i].id]=p[i+1].id,b[p[i+1].id]+=x;
}
}
int x=0,o=1;
for(int i=1;i<=n;i++)
{
if(b[i]!=0) continue;
nxt[x]=i;
while(nxt[x]!=0) x=nxt[x];
}
f[0][0][0]=ans;
for(int i=nxt[0];i;i=nxt[i],o^=1)
{
for(int j=0;j<=K;j++) f[o][j][0]=f[o][j][1]=0;
for(int j=0;j<=K;j++)
{
for(int k=0;k<=1;k++)
{
if(f[o^1][j][k]==0) continue;
f[o][j][0]=max(f[o][j][0],f[o^1][j][k]);
f[o][j+1][1]=max(f[o][j+1][1],f[o^1][j][k]+k*b[i]+a[i]);
}
}
}
cout<<max(f[o^1][K][0],f[o^1][K][1]);
cerr<<endl<<1e3*clock()/CLOCKS_PER_SEC<<"ms";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 0ms
memory: 14204kb
input:
15 50 6 13 44 8 35 30 41 25 45 10 34 14 37 2 46 12 27 7 49 24 39 19 21 3 16 18 23 4 31 36 47
output:
31
result:
ok single line: '31'
Test #2:
score: 0
Accepted
time: 2ms
memory: 14156kb
input:
20 100 10 79 87 29 82 6 34 52 92 67 71 85 90 23 56 12 27 31 91 20 97 18 93 61 88 57 73 39 74 11 13 15 63 10 42 30 99 24 49 25 59
output:
76
result:
ok single line: '76'
Test #3:
score: 0
Accepted
time: 3ms
memory: 14220kb
input:
20 1000 17 389 463 132 590 406 878 137 546 298 719 176 954 190 442 217 582 285 958 258 835 85 548 171 666 120 751 3 522 566 814 467 855 798 816 82 975 182 321 605 836
output:
953
result:
ok single line: '953'
Test #4:
score: 0
Accepted
time: 0ms
memory: 14200kb
input:
20 1000000 12 167800 346535 71130 426172 288751 794518 323809 911265 207630 564011 69094 621284 78866 643379 15243 316884 31183 689404 43019 300219 454483 531259 227350 269433 116876 538270 342869 954263 591937 823645 344280 715354 311588 463218 160089 212344 32039 710093 312736 947503
output:
855666
result:
ok single line: '855666'
Test #5:
score: 0
Accepted
time: 2ms
memory: 14200kb
input:
20 1000000 1 72506 470482 593108 593587 43028 906199 614225 626775 227792 242838 322497 907544 585011 732008 191053 265816 30742 167954 498480 785735 134759 519605 429806 514560 389366 733598 621054 663074 351512 622562 777106 869493 443978 720793 906325 985644 485517 652194 478423 704683
output:
346255
result:
ok single line: '346255'
Test #6:
score: 0
Accepted
time: 2ms
memory: 14204kb
input:
13 1000 7 171 254 378 474 131 179 68 154 679 726 775 865 723 812 292 419 466 673 578 699 195 374 43 100 23 65
output:
835
result:
ok single line: '835'
Test #7:
score: 0
Accepted
time: 0ms
memory: 14204kb
input:
20 1000000 10 46793 131716 435297 473350 304016 427066 294769 358866 134004 235514 8823 83132 291767 297727 787467 911957 752441 865182 210008 251245 239807 292945 119804 203576 587889 704218 662704 757263 899669 985074 519332 581715 551072 660494 979934 990817 440289 529980 367406 438245
output:
776965
result:
ok single line: '776965'
Test #8:
score: 0
Accepted
time: 0ms
memory: 14004kb
input:
20 55 14 40 43 30 36 11 15 28 33 1 3 34 39 42 47 14 17 24 27 38 41 16 21 6 9 22 25 8 12 2 5 19 23 51 54 45 53 26 29 4 7
output:
48
result:
ok single line: '48'
Test #9:
score: 0
Accepted
time: 0ms
memory: 14152kb
input:
20 1000000 18 858665 899603 489959 565442 590268 644418 719888 827379 960651 979260 306100 356984 439879 498028 333477 399191 843350 858934 391366 457535 10620 120202 866540 971458 817151 853286 501019 597927 645673 801465 599804 695421 257104 313332 8839 15852 250784 305182 94163 256626
output:
982782
result:
ok single line: '982782'
Test #10:
score: 0
Accepted
time: 2ms
memory: 12160kb
input:
20 987654 7 845070 849609 143653 149479 29676 77048 341336 358763 912763 923699 785024 799979 560606 562385 744571 746443 586685 604877 894532 908275 166034 179517 863401 892858 946666 952253 507043 551325 636658 662115 81161 108770 213382 222310 747170 748118 228845 292106 562956 565508
output:
885079
result:
ok single line: '885079'
Test #11:
score: 0
Accepted
time: 0ms
memory: 12104kb
input:
20 1000000 11 227132 232178 100480 104319 150105 202407 486790 512103 727178 736923 457555 474769 262604 336513 871306 911995 529680 583619 115953 125552 811496 817686 987600 990004 621029 679968 439325 452505 128976 136268 686079 688917 234565 256262 31188 44482 924943 948423 363175 401077
output:
939867
result:
ok single line: '939867'
Test #12:
score: 0
Accepted
time: 2ms
memory: 12160kb
input:
20 70 18 59 61 26 27 56 58 19 21 1 2 13 16 43 44 34 35 38 39 31 33 66 69 53 55 4 8 22 25 10 12 40 42 29 30 46 47 49 50 36 37
output:
68
result:
ok single line: '68'
Subtask #2:
score: 90
Accepted
Dependency #1:
100%
Accepted
Test #13:
score: 90
Accepted
time: 0ms
memory: 14128kb
input:
150 1000 72 249 899 352 697 203 760 810 877 12 80 682 715 175 439 726 740 21 681 414 593 526 804 138 680 618 942 293 542 164 237 617 749 49 303 190 738 665 822 124 271 337 547 412 962 232 721 710 756 484 581 514 800 77 889 356 529 374 553 148 549 577 776 332 564 131 634 48 395 623 868 264 985 415 66...
output:
763
result:
ok single line: '763'
Test #14:
score: 0
Accepted
time: 0ms
memory: 14176kb
input:
177 1428 23 177 718 849 1254 562 632 1143 1226 274 1410 164 235 641 1193 306 638 52 1290 1417 1422 234 830 656 872 381 985 895 978 390 1050 365 898 55 674 530 754 353 760 620 870 931 1308 696 1315 151 1043 658 1367 592 734 371 967 102 364 32 270 284 947 69 1419 1031 1320 961 1035 669 1372 478 545 23...
output:
583
result:
ok single line: '583'
Test #15:
score: 0
Accepted
time: 3ms
memory: 14160kb
input:
200 1000000000 131 189521847 229757350 387288649 965677465 249956539 849782120 426939514 825699422 187697365 324642681 176684455 403552922 208737582 988405287 437125903 812410093 772939356 912881607 362309399 468177930 21323674 325251441 223480546 235042406 204224262 366698978 247039691 569602359 92...
output:
898833450
result:
ok single line: '898833450'
Test #16:
score: 0
Accepted
time: 0ms
memory: 14196kb
input:
200 445 69 350 357 201 262 254 337 113 163 15 369 45 169 53 433 141 341 87 191 232 245 272 409 3 339 323 343 148 296 124 211 14 263 306 442 74 92 178 271 100 435 166 425 42 142 176 392 5 403 21 76 212 315 180 286 277 394 188 330 171 189 240 416 7 431 24 192 32 111 125 327 349 381 279 354 101 399 325...
output:
233
result:
ok single line: '233'
Test #17:
score: 0
Accepted
time: 0ms
memory: 14212kb
input:
200 1000000000 22 280166555 383798723 575170773 827017481 255721202 315768930 226890717 628846091 68987330 667934972 152897514 610232743 221051762 872802934 508226552 870906390 43328066 254130156 161260876 588642404 515462561 601358733 2730762 66630787 168819540 750110627 264891772 368804370 1082540...
output:
408001320
result:
ok single line: '408001320'
Test #18:
score: 0
Accepted
time: 3ms
memory: 14212kb
input:
156 1941 88 1752 1766 1898 1909 1888 1902 410 431 1587 1638 874 885 839 856 1553 1576 1394 1402 1399 1411 1083 1087 720 736 975 1003 1804 1822 1786 1802 1537 1557 1443 1448 1693 1704 551 560 1783 1791 313 322 20 41 1375 1381 1230 1256 1047 1077 469 490 234 245 898 931 543 557 360 394 1578 1590 769 7...
output:
1709
result:
ok single line: '1709'
Test #19:
score: 0
Accepted
time: 0ms
memory: 14152kb
input:
189 446 58 120 124 42 48 92 95 397 402 307 310 136 141 108 112 376 379 315 318 6 9 278 281 255 260 144 147 78 83 288 291 432 435 51 55 118 121 247 250 261 264 18 22 411 414 361 366 76 81 201 205 12 15 403 408 292 295 263 266 2 5 134 138 430 433 177 183 161 165 1 3 220 224 4 7 29 33 98 101 418 421 8 ...
output:
299
result:
ok single line: '299'
Test #20:
score: 0
Accepted
time: 0ms
memory: 14160kb
input:
200 1000000000 176 412431473 415804145 147541921 152836154 360257062 365155760 414622513 417858414 442364223 450350420 176387217 181717302 11824953 19031607 561985904 562524003 196136598 198728092 172132764 176569004 715299463 720943780 479000781 482996349 275795760 277949288 890212750 893838552 397...
output:
984654304
result:
ok single line: '984654304'
Test #21:
score: 0
Accepted
time: 3ms
memory: 14224kb
input:
200 1000000000 42 556835153 568681211 607266444 618651518 310061968 316199582 126203920 130964480 908515843 921543489 599537060 603845927 4630085 9278301 617647380 626419189 944077549 949578488 128111289 135642159 159891506 166093401 274398665 279105696 546865312 554941905 253392365 260911565 120510...
output:
688124178
result:
ok single line: '688124178'
Test #22:
score: 0
Accepted
time: 2ms
memory: 12176kb
input:
187 987654321 17 753418670 756321102 84556707 91139957 902999183 903267414 577843518 578988785 37356195 38529937 962923910 966556329 418299052 418793976 454764374 454781575 910822130 913795254 508998704 511922240 553138756 557264482 538760329 539609596 738680444 738940659 532390177 535004596 8838009...
output:
669127770
result:
ok single line: '669127770'
Test #23:
score: 0
Accepted
time: 0ms
memory: 12196kb
input:
200 1000000000 125 59801863 66305194 44451968 44525693 702894073 707639284 40981199 42264477 573895211 579557149 679737244 687027439 378965451 381090724 568896583 573732313 987175037 988027450 469659379 472770696 481362496 481656673 496588338 497334146 750731051 750969545 639966939 645525349 9441142...
output:
956667895
result:
ok single line: '956667895'
Test #24:
score: 0
Accepted
time: 2ms
memory: 12156kb
input:
200 487 111 316 317 343 344 134 135 161 162 181 182 419 424 86 87 283 285 321 322 192 193 157 158 297 299 53 54 213 215 397 398 106 107 113 114 261 264 431 432 339 340 439 440 208 209 259 260 357 358 30 31 247 248 345 346 451 453 295 296 445 446 25 26 201 203 363 364 251 252 84 85 459 460 469 470 21...
output:
398
result:
ok single line: '398'
Test #25:
score: 0
Accepted
time: 2ms
memory: 14232kb
input:
1999 4627 718 3488 4292 3053 3570 1263 1954 553 4478 1283 2035 2128 2173 1745 3840 2473 3738 1082 4389 1047 3983 426 1161 3311 3987 2617 2933 1773 3542 2406 2865 3184 4322 1056 1125 1638 1976 74 2487 908 3485 2068 4426 87 3116 1376 2988 3735 4099 1503 2459 3469 3711 1899 3059 453 4316 412 2718 3456 ...
output:
2529
result:
ok single line: '2529'
Test #26:
score: 0
Accepted
time: 8ms
memory: 14248kb
input:
1978 8723179 1492 2877575 4532509 2800246 3513825 1556441 6810656 6551944 7490620 2831727 5332276 1289372 8673337 3588751 4340182 5100041 8406208 3211204 8644316 1312340 3833765 5054130 5826853 444497 4431381 3054215 6596080 396974 3973611 2750230 6291675 1926053 5358070 5140986 5499518 3716062 8695...
output:
8188081
result:
ok single line: '8188081'
Test #27:
score: 0
Accepted
time: 0ms
memory: 14168kb
input:
2000 1000000000 89 125487875 587679316 44234739 807882184 770081867 846810825 244776837 768206072 383950867 653905408 272490693 565164217 414426199 769996675 900886650 996167515 380345368 706460653 774689620 874186905 259109570 428371231 233048926 773852315 457015973 501792356 95692378 285110603 273...
output:
285193088
result:
ok single line: '285193088'
Test #28:
score: 0
Accepted
time: 0ms
memory: 14248kb
input:
2000 1000000000 4 105824075 385167824 324109268 630884187 154785884 489974071 282747530 442386499 711002267 976225561 478954970 741869307 265472440 870886784 267641360 914034257 390576808 538335597 63340289 515444066 373189853 810344381 146422233 377396791 67913285 398894438 148349932 779528785 6598...
output:
172749075
result:
ok single line: '172749075'
Test #29:
score: 0
Accepted
time: 6ms
memory: 14248kb
input:
2000 1000000000 1964 269305697 625234887 271302972 435447396 159212809 888919663 155427077 714132793 140287342 996157451 308665289 626778559 275498394 699526478 593037748 943598211 86683560 145133159 46282566 540358415 558397051 963795662 13679383 376860175 641037944 935433761 653572269 668784761 50...
output:
998695997
result:
ok single line: '998695997'
Test #30:
score: 0
Accepted
time: 3ms
memory: 14148kb
input:
1995 9183813 1285 6059555 6063298 7976050 7981409 787097 788356 5598553 5600571 6740214 6745977 5386794 5391577 4242067 4249823 2723601 2736661 7346246 7350548 8314630 8322764 2883773 2891464 1615047 1623891 7327961 7332392 3516258 3531806 1522403 1530538 4456391 4459682 5996334 5997890 1492822 1498...
output:
8400624
result:
ok single line: '8400624'
Test #31:
score: 0
Accepted
time: 4ms
memory: 14224kb
input:
1972 4097 1622 3911 3914 2420 2423 841 844 2028 2031 57 61 3349 3352 2163 2167 900 903 453 456 2707 2710 2986 2989 1338 1341 1786 1789 3047 3050 3836 3840 353 356 1254 1257 3724 3727 1020 1023 762 765 349 352 529 532 2333 2336 3435 3438 1907 1910 3494 3497 1109 1112 2344 2347 3000 3003 1565 1568 185...
output:
3744
result:
ok single line: '3744'
Test #32:
score: 0
Accepted
time: 5ms
memory: 14232kb
input:
2000 1000000000 1782 210598857 211371319 22856529 23485211 8330545 8597988 169628588 170163407 216667781 217445383 984299301 985996940 119676055 120428823 52848647 53953609 675409282 675754885 268459293 268874921 851378463 851761392 22958906 24347973 559351085 560707100 813860813 815645368 812951402...
output:
985889095
result:
ok single line: '985889095'
Test #33:
score: 0
Accepted
time: 3ms
memory: 14208kb
input:
2000 1000000000 27 726502161 727288287 480881899 482360112 26693388 27160634 852366277 852853778 777790658 778806905 856749689 857760719 477447606 478623644 552222284 553114017 746118805 746477088 532631588 533157310 348821250 349215523 35007445 36164242 66839304 67704320 85345644 85635811 973789685...
output:
527289966
result:
ok single line: '527289966'
Test #34:
score: 0
Accepted
time: 3ms
memory: 12180kb
input:
1987 987654321 1183 569581413 569589256 383934317 383980443 497431375 497437392 327329235 327813151 277898638 277918928 336959886 337050112 201199442 201278694 950150202 950242539 330609607 330755687 308903810 308929632 12441472 12524273 118023069 118137366 722258795 723337011 954554287 954727152 29...
output:
942404808
result:
ok single line: '942404808'
Test #35:
score: 0
Accepted
time: 7ms
memory: 12168kb
input:
2000 1000000000 1632 877903189 878719671 797997919 798261285 466750585 466869351 127154649 127288892 720673108 720723670 611411576 611571480 629330384 629720274 108745004 108779368 59749557 59851764 11679984 11783535 823204905 823334936 941224920 941356486 373174428 373195941 292110980 292274567 970...
output:
990972241
result:
ok single line: '990972241'
Test #36:
score: 0
Accepted
time: 8ms
memory: 12180kb
input:
2000 5183 1922 3305 3306 2031 2032 1097 1098 550 552 3279 3282 1610 1611 1910 1911 5097 5098 4774 4776 4941 4944 4140 4141 4281 4285 2332 2333 1452 1453 880 882 3195 3196 2149 2150 2737 2738 52 54 786 788 4970 4971 3252 3253 3376 3377 4396 4397 2249 2250 295 296 4578 4579 4246 4247 358 359 3095 3096...
output:
5105
result:
ok single line: '5105'
Extra Test:
score: 0
Extra Test Passed