QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#109551#71. Cake 3bashkort#5 13ms3948kbC++201.2kb2023-05-29 17:55:062024-05-31 13:47:20

Judging History

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

  • [2024-05-31 13:47:20]
  • 评测
  • 测评结果:5
  • 用时:13ms
  • 内存:3948kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-29 17:55:06]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr int N = 101;

ll V[N], C[N], V_[N], C_[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    for (int i = 0; i < n; ++i) {
        cin >> V[i] >> C[i];
        V[i] -= 2 * C[i];
    }

    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j) {
        return C[i] < C[j];
    });

    memcpy(V_, V, sizeof(V));
    memcpy(C_, C, sizeof(C));

    for (int i = 0; i < n; ++i) {
        C[i] = C_[ord[i]];
        V[i] = V_[ord[i]];
    }

    ll ans = -3e18;

    for (int s = 0; s < n; ++s) {
        memset(dp, -0x3f, sizeof(dp));
        dp[s][1] = V[s];

        for (int i = s + 1; i < n; ++i) {
            for (int p = s; p < i; ++p) {
                for (int m = 1; m < k; ++m) {
                    dp[i][m + 1] = max(dp[i][m + 1], dp[p][m] + V[i] + 2 * min(C[i], C[p]));
                }
            }
            ans = max(ans, dp[i][k] + 2 * min(C[i], C[s]));
        }
    }

    cout << ans << '\n';

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 5ms
memory: 3752kb

input:

100 32
671208774 266481733
115497791 342597239
326245300 76223942
528973483 754205900
437996819 995535247
100582194 42402057
771100621 351934207
89058009 81951602
768935397 186435060
842907845 376386254
187943947 59424920
997369107 493642356
455078419 68850493
542835555 938351581
970171972 611243076...

output:

25580474644

result:

ok single line: '25580474644'

Test #2:

score: 5
Accepted
time: 4ms
memory: 3644kb

input:

96 26
654901552 458347153
165510759 938829925
195217130 507375330
505924632 413472221
654752848 711653336
843934470 721570198
773665886 401710037
234904469 980379861
955790468 908963841
767941919 649831102
551860594 482287589
445315312 465411688
121261567 38031091
85608696 831434175
898543690 533481...

output:

20912597347

result:

ok single line: '20912597347'

Test #3:

score: 5
Accepted
time: 7ms
memory: 3708kb

input:

97 50
601727246 586947184
629061466 495053188
908476392 789027930
127214423 866336725
518731382 132785533
113489768 827723755
985313205 850125600
651615014 585565934
7844301 974793551
821451342 503266415
191392244 172018292
811053096 980886405
414007158 116164410
749815864 858185057
809840877 654635...

output:

35572528711

result:

ok single line: '35572528711'

Test #4:

score: 5
Accepted
time: 7ms
memory: 3716kb

input:

95 53
149550762 262774006
70645562 988470529
951317142 587455395
640797744 881023050
152099375 109591790
42073955 240106850
787394186 32306392
690229700 154829125
612427906 799230609
529294971 846139787
399369072 840851479
258683206 624167919
933584741 989196725
928112368 809131208
742906726 7228213...

output:

38104623964

result:

ok single line: '38104623964'

Test #5:

score: 5
Accepted
time: 9ms
memory: 3652kb

input:

95 67
219655106 209971230
684228500 55963835
376681839 957451928
44063570 464399636
244459351 255445846
926539875 699539831
624720901 149661354
268068448 124041530
391618918 196971593
259894666 522352998
72651673 750483217
418558834 288939175
987660441 756241680
290013706 540390088
672554190 1595528...

output:

42726885227

result:

ok single line: '42726885227'

Test #6:

score: 5
Accepted
time: 10ms
memory: 3708kb

input:

98 83
144189007 599184430
955720138 430137031
46813950 337012077
284624496 923370172
585878255 277696686
458874123 25220195
65996741 918738892
536999214 420249860
124871436 785740035
524616035 321557657
377122912 363899088
800060966 799482628
704695498 739563311
385588901 543586072
594428502 6483895...

output:

47720376527

result:

ok single line: '47720376527'

Test #7:

score: 5
Accepted
time: 6ms
memory: 3684kb

input:

96 38
37921502 265183642
30462271 269145614
51895518 29824956
44764507 681512686
47724467 815499441
6427327 591731270
46504734 436644698
2223048 132007665
40380520 511674250
43917077 653531209
17511337 975498424
1931641 115779401
16884852 128795730
14731353 429591965
5850509 790146440
15255306 77070...

output:

399264493

result:

ok single line: '399264493'

Test #8:

score: 5
Accepted
time: 2ms
memory: 3684kb

input:

96 25
57401007 493943697
29527957 714663679
29545307 647011203
41025179 566266756
58441740 117870293
27412280 422916085
33052858 310233747
9411800 715114198
15661682 773129023
49930623 903197292
4733526 653650922
36089642 500031319
1389486 444206729
19886177 397683562
2903725 764846753
84795 2145521...

output:

719815801

result:

ok single line: '719815801'

Test #9:

score: 5
Accepted
time: 4ms
memory: 3916kb

input:

99 21
59657805 652963568
80731103 249217474
67765017 136600735
30669693 235796790
38336275 333697289
9339946 754166690
69051138 182211402
93041255 259466527
71372493 445676674
67165121 840321934
33766102 430254036
18248715 148433501
38354832 282537749
64069877 131281615
39361263 592884334
18160924 9...

output:

888797889

result:

ok single line: '888797889'

Test #10:

score: 5
Accepted
time: 3ms
memory: 3948kb

input:

93 28
19252348 834865987
35189109 821648351
47848765 934801179
33900007 907328375
45481720 478428955
4292036 880931858
36991135 956842947
49181931 583677473
36889879 714660270
20737289 866325358
65602596 635999283
70856516 855441876
54559432 319956854
47217522 132918942
55127890 62037126
53412038 84...

output:

597761343

result:

ok single line: '597761343'

Test #11:

score: 5
Accepted
time: 0ms
memory: 3716kb

input:

92 18
17034692 311412535
75067760 700238328
85371763 32662981
90417142 594066624
34625146 420051930
46026136 298353430
71930456 679253686
94901612 553915166
10855990 339449028
10327620 444733804
51133091 802733614
95838938 276886845
22327317 53898064
29910663 881733161
74599342 280465633
8898777 221...

output:

963264484

result:

ok single line: '963264484'

Test #12:

score: 5
Accepted
time: 6ms
memory: 3712kb

input:

96 46
3613091 48226953
17333738 315657491
33499557 905024
21585984 973060800
42148202 275277748
25892629 489251559
31604703 888333915
13970358 799610574
33246317 54304803
7114447 61375639
5669373 697687696
1575366 350398758
16667098 747366614
7839377 799378407
18868553 430864652
41883674 476142622
1...

output:

217389025

result:

ok single line: '217389025'

Test #13:

score: 5
Accepted
time: 7ms
memory: 3644kb

input:

100 45
43924230 212784715
43573365 390630448
36356410 302155896
8834549 369231487
23914662 209393152
8961292 339488011
11770598 98213199
41391432 553642288
33929359 654885451
15834215 243511760
32889505 785116193
40157572 806063390
41729010 657312356
24502770 98898149
33168308 379445567
25788178 737...

output:

284124804

result:

ok single line: '284124804'

Test #14:

score: 5
Accepted
time: 2ms
memory: 3708kb

input:

94 44
18278964 59117371
1121774 674793869
44776633 866596597
3672456 43798662
18327992 258671822
26820827 436747027
10741961 269663794
4454544 235521073
2959148 111403543
17994812 431349737
44808537 631076314
1072950 366206930
37219572 987766907
33824148 367550034
18542970 307178475
1386716 33940913...

output:

308368925

result:

ok single line: '308368925'

Test #15:

score: 5
Accepted
time: 5ms
memory: 3916kb

input:

96 41
36332583 8569405
20284590 704164692
26169208 400229170
32850340 485895095
44691003 149746532
5684161 537586304
3545889 108210000
26693523 480026681
38944140 61394964
34125662 576589094
10604727 179814783
12192083 364751818
37385170 791694556
20134304 90024835
19149660 168146967
11032310 183184...

output:

344295172

result:

ok single line: '344295172'

Test #16:

score: 5
Accepted
time: 4ms
memory: 3876kb

input:

90 38
8869730 76738045
32276119 757676479
5091410 369590827
35491028 689930909
20025995 127998287
49111097 975894312
16776797 690236150
14603906 430533164
6638017 768678637
583367 277491929
43583227 197845857
19225748 735413656
39437324 641580882
43275662 785441666
50322818 734853329
35990613 997504...

output:

418654054

result:

ok single line: '418654054'

Test #17:

score: 5
Accepted
time: 8ms
memory: 3656kb

input:

97 63
17888788 608002691
16142900 885752870
1364666 365868015
4878248 624150124
18576418 704242346
17020617 375882628
21749764 987510302
23736619 444353886
19722113 954714013
9275566 579405076
31641382 557924314
28779133 996785377
24059182 892591765
26116965 249236656
15958669 36018002
12783153 4066...

output:

-324021706

result:

ok single line: '-324021706'

Test #18:

score: 5
Accepted
time: 9ms
memory: 3656kb

input:

100 71
14246084 541505816
9994802 994431615
1482902 185840951
26468202 241171629
17716658 549877382
25340166 772809756
18151090 18915661
10164740 748716089
12552723 56489026
6069755 574352885
23096929 778200711
24642227 384490457
4716312 797733167
23906409 557004993
197262 5593534
27176008 844798422...

output:

-276543166

result:

ok single line: '-276543166'

Test #19:

score: 5
Accepted
time: 5ms
memory: 3948kb

input:

97 65
4386932 310542657
23651846 24902512
17872222 432076283
12688150 320458048
13294064 783055998
24489246 667018801
26933633 303216574
20987206 894751368
6946734 18906053
4725483 816674619
11278516 963601520
1714355 137847174
16817734 79470468
7807193 972225264
15832623 861238054
11363869 91575309...

output:

-174786613

result:

ok single line: '-174786613'

Test #20:

score: 5
Accepted
time: 10ms
memory: 3752kb

input:

100 76
19363945 999230932
6565531 340746079
17098814 481571520
15063962 562888079
16400153 379641015
22687207 473072780
13205572 315563624
4971425 266006726
25882141 800667318
16425184 781371894
10021910 67574149
19963913 96397646
26310382 585714937
7145348 578506544
4794238 790460340
7285540 645057...

output:

-310560206

result:

ok single line: '-310560206'

Test #21:

score: 5
Accepted
time: 8ms
memory: 3656kb

input:

95 66
12740392 44322988
23072578 479866996
28690034 991246669
23341774 816240165
5356957 510095701
6993836 351625358
16797983 601213241
16864568 335398045
13997193 909507175
27087288 982552754
26886506 169380803
3047418 849902451
1896289 226928494
1306707 244984996
13019901 587922276
11247618 716796...

output:

-28999886

result:

ok single line: '-28999886'

Test #22:

score: 5
Accepted
time: 3ms
memory: 3660kb

input:

94 22
17729830 195028137
17729832 195028150
17729830 195028178
17729832 195028140
17729832 195028118
17729836 195028176
17729835 195028180
17729829 195028198
17729829 195028141
17729835 195028132
17729834 195028115
17729829 195028197
17729829 195028160
17729829 195028137
17729834 195028161
17729836 ...

output:

390056298

result:

ok single line: '390056298'

Test #23:

score: 5
Accepted
time: 4ms
memory: 3948kb

input:

100 25
15180379 189754751
15180379 189754772
15180385 189754771
15180385 189754771
15180379 189754773
15180385 189754781
15180383 189754741
15180381 189754720
15180381 189754791
15180385 189754788
15180381 189754771
15180384 189754718
15180379 189754738
15180384 189754779
15180386 189754788
15180379...

output:

379509524

result:

ok single line: '379509524'

Test #24:

score: 5
Accepted
time: 5ms
memory: 3656kb

input:

92 37
6917252 127969112
6917251 127969122
6917248 127969158
6917252 127969121
6917249 127969098
6917249 127969063
6917252 127969064
6917251 127969071
6917250 127969096
6917249 127969144
6917250 127969080
6917251 127969129
6917248 127969134
6917248 127969134
6917251 127969112
6917248 127969112
691724...

output:

255938190

result:

ok single line: '255938190'

Test #25:

score: 5
Accepted
time: 7ms
memory: 3664kb

input:

100 42
8947720 187902126
8947719 187902145
8947719 187902174
8947722 187902111
8947720 187902164
8947722 187902148
8947723 187902141
8947721 187902138
8947719 187902143
8947720 187902154
8947722 187902170
8947721 187902162
8947721 187902079
8947719 187902111
8947719 187902094
8947721 187902129
89477...

output:

375804228

result:

ok single line: '375804228'

Test #26:

score: 5
Accepted
time: 5ms
memory: 3724kb

input:

93 42
5450766 114466000
5450765 114466073
5450765 114466092
5450763 114466006
5450765 114466065
5450764 114466073
5450764 114466016
5450764 114466092
5450765 114466060
5450764 114466069
5450765 114466002
5450763 114466020
5450766 114466040
5450766 114466051
5450767 114466080
5450763 114466002
545076...

output:

228932048

result:

ok single line: '228932048'

Test #27:

score: 5
Accepted
time: 2ms
memory: 3916kb

input:

96 42
6481674 136115141
6481674 136115143
6481674 136115200
6481677 136115104
6481674 136115173
6481673 136115198
6481672 136115171
6481674 136115171
6481674 136115198
6481676 136115115
6481674 136115159
6481673 136115179
6481674 136115123
6481674 136115116
6481676 136115173
6481673 136115132
648167...

output:

272230243

result:

ok single line: '272230243'

Test #28:

score: 5
Accepted
time: 4ms
memory: 3688kb

input:

91 35
7078729 127852986
6976330 199120225
7918266 101649053
9886390 174239569
8680498 181231369
10147698 178133237
6550286 188440017
10998842 176674437
11338474 163404734
9928237 144614674
10813308 119730850
8490207 177630658
7666339 125985790
8842506 161567810
7545945 172836768
7244339 151363289
88...

output:

257081558

result:

ok single line: '257081558'

Test #29:

score: 5
Accepted
time: 3ms
memory: 3728kb

input:

90 22
14286146 154004991
16643150 170148576
14468260 179044873
11596207 178516095
16788739 193967231
12440449 168662547
14797798 174924503
11195707 136243477
12044575 129447384
9432188 100337673
17144187 104480992
11072522 110866789
13775415 155063112
17184094 100533600
12446867 176287486
11478110 1...

output:

281555721

result:

ok single line: '281555721'

Test #30:

score: 5
Accepted
time: 4ms
memory: 3708kb

input:

100 29
9531137 158342198
10547622 178461072
11919343 157206544
9587137 162255834
8112842 138118096
7650771 117964254
7497546 137803698
9171970 168188367
13214044 159075986
13332882 177627982
13251626 191514575
8195217 135984932
10266960 188825369
8135290 153570161
12177239 158413233
10303999 1774730...

output:

281996167

result:

ok single line: '281996167'

Test #31:

score: 5
Accepted
time: 3ms
memory: 3748kb

input:

95 49
5324636 179288160
5409006 130652095
6846457 160463725
4338673 104140314
5324593 179288197
5322187 185899122
6179346 148685923
7003579 184887841
6834578 172632756
5094797 186909136
6317848 135586449
5356447 183268322
5803751 184007780
6846531 160463782
5414770 141547042
5398293 191301500
631790...

output:

231995752

result:

ok single line: '231995752'

Test #32:

score: 5
Accepted
time: 2ms
memory: 3656kb

input:

92 47
8061822 136846833
6642446 166843406
4261250 160921666
4489059 151015120
4601597 135229263
4824447 154004434
6525893 153559993
7417252 146176344
6153011 191410359
4464747 159984984
8343467 111098444
4504883 137911904
5927740 185005343
8351538 181377851
4489006 151015089
4824407 154004364
842467...

output:

218822483

result:

ok single line: '218822483'

Test #33:

score: 5
Accepted
time: 4ms
memory: 3712kb

input:

92 39
9027696 183506931
5961251 142108073
7720700 110598847
5648540 196652092
6501150 189219306
5746162 187475921
8410833 143213540
9004401 141124014
7671741 174085402
9961580 141717536
8226371 157513143
9747707 179135409
9740001 118326279
9281457 126779638
9945648 114139725
9747637 179135416
722782...

output:

274033436

result:

ok single line: '274033436'

Test #34:

score: 5
Accepted
time: 6ms
memory: 3884kb

input:

92 55
1 1
10 490
6 979
2 1468
4 1957
2 2446
6 2935
7 3424
9 3913
3 4402
3 4891
5 5380
1 5869
2 6358
8 6847
1 7336
5 7825
9 8314
1 8803
10 9292
8 9781
1 10270
6 10759
7 11248
4 11737
4 12226
3 12715
5 13204
10 13693
3 14182
8 14671
8 15160
5 15649
2 16138
9 16627
4 17116
2 17605
6 18094
7 18583
10 19...

output:

-52489

result:

ok single line: '-52489'

Test #35:

score: 5
Accepted
time: 3ms
memory: 3664kb

input:

90 27
2 1
5 466
2 931
7 1396
10 1861
10 2326
4 2791
1 3256
10 3721
4 4186
2 4651
4 5116
10 5581
9 6046
5 6511
10 6976
4 7441
6 7906
9 8371
4 8836
10 9301
8 9766
10 10231
2 10696
9 11161
1 11626
5 12091
6 12556
3 13021
7 13486
4 13951
10 14416
8 14881
4 15346
6 15811
5 16276
3 16741
4 17206
10 17671
...

output:

-24008

result:

ok single line: '-24008'

Test #36:

score: 5
Accepted
time: 0ms
memory: 3708kb

input:

96 23
466703636 1
685964430 1
94138746 1
260865796 1
671061690 1
342965956 1
70077955 1
353576592 1
647102711 1
381407841 1
160479125 1
532426710 1
606287881 1
815834411 1
154155710 1
173295822 1
79893082 1
977723022 1
449558013 1
697003683 1
409420108 1
18515297 1
663646483 1
396590913 1
184119427 ...

output:

20219731188

result:

ok single line: '20219731188'

Test #37:

score: 5
Accepted
time: 13ms
memory: 3748kb

input:

100 100
865613444 566253861
658651559 846380264
825752153 192037838
448174355 534315715
739996438 168524064
81511958 137624584
852893078 662698922
719896249 803133529
562555332 7146132
266184989 611936568
885582195 736804493
521264825 67715872
474677299 497782030
224795664 930773965
613758079 961250...

output:

45696374824

result:

ok single line: '45696374824'

Subtask #2:

score: 0
Runtime Error

Dependency #1:

100%
Accepted

Test #38:

score: 0
Runtime Error

input:

1855 501
338527451 578733742
703170142 682868070
16985949 852452962
662029309 680590695
717678423 220285590
961443168 146607690
278716170 683348763
238103085 414255420
332431596 320585514
501489988 647737182
293979999 420745717
402085021 831124117
569170680 735252719
136204202 448222008
296743227 74...

output:


result:


Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%