Source Code
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define sim template <class c
#define ris return *this
#define dor > debug& operator<<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) {
    return rge<c>{i, j};
}
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
    ~debug() {
        cerr << endl;
    }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) {
        ris;
    }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int N = 1001000;
const ll INF = 1e18;

int a[N], b[N], c[N], d[N];

ll p[N];
ll dp[N];
ll best[N];

int main() {
    int n, m;
    cin >> n >> m;

    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
    }

    for (int i = 1; i <= n; i++) {
        scanf("%d", c + i);
        p[i] = (c[i] > 0 ? c[i] : 0) + p[i - 1];
    }

    for (int i = 1; i <= m; i++) {
        scanf("%d", b + i);
        d[b[i]] = i;
    }

    // debug() << imie(range(a + 1, a + n + 1));
    // debug() << imie(range(c + 1, c + n + 1));
    // debug() << imie(range(p + 1, p + n + 1));
    // debug() << imie(range(b + 1, b + m + 1));
    // debug() << imie(range(d + 1, d + n + 1));

    dp[0] = 0;
    best[0] = dp[0] - p[0];

    for (int x = 1; x <= n; x++) {
        best[x] = -INF;
    }

    for (int i = 1; i <= n; i++) {
        int j = d[a[i]];
        if (j > 0) {
            int x = b[j], y = b[j - 1];
            dp[i] = c[i] + p[i - 1] + best[y];
            best[x] = max(best[x], dp[i] - p[i]);
        }
    }

    // debug() << imie(range(dp, dp + n + 1));

    ll answer = -INF;
    for (int i = 1; i <= n; i++) {
        if (a[i] == b[m]) {
            answer = max(answer, dp[i] + p[n] - p[i]);
        }
    }

    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        sum += c[i];
    }

    // debug() << imie(sum) imie(answer);

    cout << sum - answer << endl;
}
Copy
Always with Me, Always with You Baraa_Armoush
GNU G++17
187 ms
34.5 MB
Accepted
Test Case #1
0 ms
360 KB
Accepted
Input
5 3
1 2 3 4 5
-5 -19 -1 0 3
2 4 5
Output
-6
Judge Output
-6
Checker Message
1 number(s): "-6"
Test Case #2
0 ms
544 KB
Accepted
Input
6 3
1 3 3 2 4 6
-1 -5 -10 4 -3 5
1 3 2
Output
-13
Judge Output
-13
Checker Message
1 number(s): "-13"
Test Case #3
187 ms
31.4 MB
Accepted
Input
843011 284344
204413 836398 355806 31659 26969 738059 454230 350554 385660 707917 55805 635287 206665 342540 256464 639213 450692 323956 300329 468413 560351 230330 422123 299226 22694 161527 257471 226590 729768 338731 112644 816419 815105 621033 4...
Output
-139487201339
Judge Output
-139487201339
Checker Message
1 number(s): "-139487201339"
Test Case #4
155 ms
34.5 MB
Accepted
Input
959139 16287
171222 691779 108308 149522 39595 511188 691989 878385 781014 13325 449496 497051 819690 501313 181687 103013 535764 649875 233948 11335 851333 443914 294974 272383 591272 127149 642499 407867 531993 563630 934723 955271 856749 158197 3...
Output
-235603637175
Judge Output
-235603637175
Checker Message
1 number(s): "-235603637175"
Test Case #5
2 ms
1.1 MB
Accepted
Input
9859 1129
9594 7009 7009 312 9436 2353 2848 9201 7096 8431 9771 1764 2663 8032 5867 3351 8007 5043 7043 7567 7291 2249 3112 3613 2414 6106 1546 4724 2163 1331 2259 9777 4952 2144 2955 7244 4550 1993 3903 3861 6371 5534 3801 9421 728 6798 9225 8196 5...
Output
-2165384711
Judge Output
-2165384711
Checker Message
1 number(s): "-2165384711"
Test Case #6
23 ms
5.3 MB
Accepted
Input
125987 33039
93253 13300 77237 96514 80638 103694 103405 3859 13073 95888 33313 810 61116 31261 86495 65002 116142 122033 4486 46756 21962 107335 73612 79201 117131 31853 66850 108288 85848 78218 105599 89082 68173 28225 40907 79371 32802 20117 734...
Output
-23223125660
Judge Output
-23223125660
Checker Message
1 number(s): "-23223125660"
Test Case #7
39 ms
8.3 MB
Accepted
Input
209411 57052
73463 91412 90004 204015 56989 37390 59014 55560 13723 192964 56596 113283 180976 23809 62192 139963 1068 116304 39140 194781 21192 196478 111077 119400 191632 155740 166644 8571 77100 104754 178076 112442 204468 112714 138678 110874 10...
Output
-37866744325
Judge Output
-37866744325
Checker Message
1 number(s): "-37866744325"
Test Case #8
57 ms
12.5 MB
Accepted
Input
325539 44339
305560 237387 198767 92527 235020 16720 103639 288504 141839 39022 257214 219063 7883 249082 16113 26579 63440 22288 26931 10428 195075 28419 4183 302420 294035 60919 266637 132608 4115 136869 75130 180796 290719 233705 127228 38983 118...
Output
-69920978550
Judge Output
-69920978550
Checker Message
1 number(s): "-69920978550"
Test Case #9
66 ms
14.2 MB
Accepted
Input
376259 55450
316532 99765 23908 62374 234174 224105 315720 4484 211416 151659 254338 156817 8724 260263 285226 241552 218755 97802 87688 115665 17436 45850 271700 21532 16245 71017 351550 30653 321865 159351 240899 282956 44730 92424 64882 186165 16...
Output
-80077995171
Judge Output
-80077995171
Checker Message
1 number(s): "-80077995171"
Test Case #10
87 ms
18.2 MB
Accepted
Input
492387 64924
273583 291185 225613 299059 369847 404793 255867 448154 450988 351785 194769 387314 380930 438733 122234 302234 325212 145357 6033 97336 332453 471032 57 349222 59460 463484 59599 163273 216871 45086 420989 259519 24686 270626 398908 50...
Output
-106670370152
Judge Output
-106670370152
Checker Message
1 number(s): "-106670370152"
Test Case #11
121 ms
22.9 MB
Accepted
Input
608515 184272
327601 565298 401487 398269 213158 194579 220710 312264 391147 341165 608215 311919 357281 304567 510223 586314 59415 576794 153098 174828 224643 263941 118259 395900 85330 189209 116236 530792 136872 472349 435661 373024 135979 522061...
Output
-105628907948
Judge Output
-105628907948
Checker Message
1 number(s): "-105628907948"
Test Case #12
140 ms
25.9 MB
Accepted
Input
691939 215535
379374 286897 686155 117764 654641 106877 21116 220414 92863 190039 280618 583002 333928 568644 486865 282756 456590 356819 420360 370676 647447 69037 80911 237293 623118 93651 137555 13850 577493 513892 675584 194344 182787 435093 523...
Output
-119236367922
Judge Output
-119236367922
Checker Message
1 number(s): "-119236367922"
Test Case #13
6 ms
1.9 MB
Accepted
Input
30518 11980
7425 11457 22445 9110 24955 18091 14278 25730 27913 28845 18799 741 21045 6037 1491 11491 15934 137 28782 20072 11285 19964 4760 16534 12398 13069 841 15660 22833 7460 20999 2601 2640 6058 23902 5732 20149 27786 27985 20054 7329 25075 28...
Output
-4602763095
Judge Output
-4602763095
Checker Message
1 number(s): "-4602763095"
Test Case #14
27 ms
6.1 MB
Accepted
Input
146646 38949
56264 47069 110693 137778 109688 45077 101694 135518 53775 115983 87463 33958 98642 37796 72189 15267 118242 36161 113757 17602 95700 132037 139269 139790 14133 143432 58902 106656 7 26034 76858 75811 32001 15207 134982 1752 45926 72374...
Output
-26927962185
Judge Output
-26927962185
Checker Message
1 number(s): "-26927962185"
Test Case #15
37 ms
8.8 MB
Accepted
Input
230070 2408
81684 61837 73392 181771 145186 190333 11737 15648 178937 37388 138665 105193 54745 73271 227894 64549 109496 213802 25699 218383 202771 95018 18328 118043 162752 140671 30054 4590 200195 219494 110731 1930 194427 141001 93262 186495 103...
Output
-56676638391
Judge Output
-56676638391
Checker Message
1 number(s): "-56676638391"
Test Case #16
54 ms
12.0 MB
Accepted
Input
313494 40548
243222 302646 188522 290830 251241 293987 182331 270267 303514 46534 16397 85582 39866 13424 216414 131997 97918 134277 124702 24409 103687 176957 112237 229599 302383 8431 257980 113809 134597 65829 248908 49068 164362 242341 298346 95...
Output
-68015933689
Judge Output
-68015933689
Checker Message
1 number(s): "-68015933689"
Test Case #17
71 ms
15.0 MB
Accepted
Input
396918 73859
37659 142570 65745 126811 319256 134567 88788 67971 49100 284744 95896 230602 279583 118791 269041 193328 109785 339308 213412 241271 309130 217915 355290 322965 245539 15528 289487 364403 259565 164291 159235 14668 361349 63477 19325 2...
Output
-80677494179
Judge Output
-80677494179
Checker Message
1 number(s): "-80677494179"
Test Case #18
92 ms
19.2 MB
Accepted
Input
513046 94874
239345 250615 88211 373410 511570 268835 84944 52187 270013 21971 58218 418607 114254 462660 128197 289500 317819 51344 203907 16482 434445 215262 411901 134689 97270 44527 492259 383927 18403 80218 143389 75399 88338 273803 468735 4451...
Output
-104341079865
Judge Output
-104341079865
Checker Message
1 number(s): "-104341079865"
Test Case #19
147 ms
23.3 MB
Accepted
Input
629174 98109
148241 388707 33676 377652 256013 602781 360079 236737 339853 281505 500974 71312 344675 215016 351316 618000 321467 291303 255479 32210 13763 246055 581022 441316 329713 272224 310181 590167 136723 233532 610996 474979 276702 456627 27...
Output
-132615827517
Judge Output
-132615827517
Checker Message
1 number(s): "-132615827517"
Test Case #20
127 ms
25.2 MB
Accepted
Input
679894 135716
129932 443221 185324 234067 107010 306347 408121 628538 73197 126439 528050 615961 327650 523509 379432 376202 232501 609904 518472 316808 40108 159956 369871 437136 482730 13 517582 404766 370842 646602 421825 317879 287833 508082 402...
Output
-136112182464
Judge Output
-136112182464
Checker Message
1 number(s): "-136112182464"
Test Case #21
147 ms
29.3 MB
Accepted
Input
796022 146179
755568 489568 251888 767352 27783 42021 669588 738802 374954 361532 204859 126541 364755 525484 389904 256665 104163 461643 445074 441700 145549 310121 568322 790672 160667 299652 659540 758090 80676 196457 49160 753058 18822 121362 71...
Output
-162423213982
Judge Output
-162423213982
Checker Message
1 number(s): "-162423213982"
Test Case #22
159 ms
32.0 MB
Accepted
Input
879446 58527
386222 32972 127385 793671 727209 569507 318746 370242 158536 648800 402511 176652 520316 646343 439383 502177 85965 564129 392717 97963 577581 787105 855127 452528 827876 834759 347644 715520 516500 255159 467817 297914 187031 453004 1...
Output
-205007359739
Judge Output
-205007359739
Checker Message
1 number(s): "-205007359739"
Test Case #23
87 ms
15.5 MB
Accepted
Input
405440 123353
94761 356620 154210 209574 361914 247550 291084 256080 269716 99261 360710 228158 82778 385813 53419 336900 13121 256899 301740 85292 108819 277497 61579 175474 207725 112736 286626 288006 119040 118673 9882 26254 48147 385819 307956 3...
Output
-70313171828
Judge Output
-70313171828
Checker Message
1 number(s): "-70313171828"
Test Case #24
0 ms
760 KB
Accepted
Input
11 1
8 11 2 7 6 2 2 11 11 5 4
-72535 242125 -614762 564337 -801184 223424 -916504 -284025 749863 555219 232927
4
Output
-2689010
Judge Output
-2689010
Checker Message
1 number(s): "-2689010"
Test Case #25
0 ms
760 KB
Accepted
Input
19 4
13 8 8 11 18 12 9 15 19 6 13 11 11 17 9 14 2 18 1
-773525 667743 -455881 -281685 -62054 -906946 437055 985148 92827 -556692 -761880 -585919 -715650 -458613 786599 -567343 -354423 -306652 768104
6 13 18 1
Output
-5162039
Judge Output
-5162039
Checker Message
1 number(s): "-5162039"
Test Case #26
0 ms
760 KB
Accepted
Input
19 1
16 5 10 16 8 14 3 7 7 5 6 13 7 6 4 8 11 11 2
-833694 -314484 -65849 -558019 871351 879536 -746029 -596358 -416230 167877 -870105 846406 424172 303291 954604 -594801 -975353 -230704 512835
2
Output
-6201626
Judge Output
-6201626
Checker Message
1 number(s): "-6201626"
Test Case #27
0 ms
800 KB
Accepted
Input
7 4
2 2 2 1 5 5 4
203568 112535 505355 -938946 512548 -194044 -596342
2 1 5 4
Output
-194044
Judge Output
-194044
Checker Message
1 number(s): "-194044"
Test Case #28
0 ms
824 KB
Accepted
Input
11 2
9 3 6 6 1 10 9 9 8 5 2
-247409 -364625 983397 598947 887806 934025 216899 149680 987459 990977 514201
3 6
Output
-247409
Judge Output
-247409
Checker Message
1 number(s): "-247409"
Test Case #29
0 ms
812 KB
Accepted
Input
19 7
10 18 4 18 18 1 14 3 5 11 2 6 1 6 6 7 1 17 12
938112 769226 -477915 63905 584891 716806 -112126 362002 695306 110267 498219 -510517 49920 811146 -846308 913162 703774 664846 -960599
18 14 11 1 7 17 12
Output
-1834740
Judge Output
-1834740
Checker Message
1 number(s): "-1834740"
Test Case #30
0 ms
796 KB
Accepted
Input
19 6
11 1 6 4 9 15 13 8 11 10 6 8 10 14 13 19 10 11 19
771150 274355 312632 -915428 -350568 845232 -668878 977982 -873206 -276423 -127131 807255 691933 197071 -782169 936939 -29783 -183850 243184
15 10 6 8 14 11
Output
-3620032
Judge Output
-3620032
Checker Message
1 number(s): "-3620032"
Test Case #31
0 ms
796 KB
Accepted
Input
7 3
2 6 3 5 2 4 3
427362 823146 -279442 -491151 -176394 254614 -797197
3 5 2
Output
-797197
Judge Output
-797197
Checker Message
1 number(s): "-797197"
Test Case #32
0 ms
932 KB
Accepted
Input
15 5
11 8 12 9 3 4 10 4 12 5 10 14 11 7 13
-690131 654991 615067 -317985 -445247 438616 -100620 248923 -836428 -927925 -9235 990531 834505 308676 -206139
12 9 4 10 7
Output
-3206490
Judge Output
-3206490
Checker Message
1 number(s): "-3206490"
Test Case #33
0 ms
932 KB
Accepted
Input
19 7
12 1 19 7 13 14 6 4 9 16 15 15 11 19 2 13 13 18 12
-968081 771198 -223049 850580 -136146 891076 -737025 -353040 -507666 256705 -552920 794330 802792 280660 -372969 -567865 213073 297936 696723
12 1 7 6 16 19 13
Output
-2713655
Judge Output
-2713655
Checker Message
1 number(s): "-2713655"
Test Case #34
0 ms
800 KB
Accepted
Input
18 1
9 15 9 8 17 17 18 2 17 9 17 13 13 17 15 5 2 15
-72069 -395358 -523453 -511446 854898 -846967 -749453 -341866 173256 -508156 574073 878761 984359 798117 -622388 434663 264157 607113
15
Output
-4571156
Judge Output
-4571156
Checker Message
1 number(s): "-4571156"
Test Case #35
0 ms
864 KB
Accepted
Input
6 1
2 5 5 6 2 5
373822 -38674 810464 61566 813177 945100
5
Output
-38674
Judge Output
-38674
Checker Message
1 number(s): "-38674"
Test Case #36
0 ms
800 KB
Accepted
Input
10 6
4 7 2 1 6 3 7 8 7 8
986234 -456379 -810222 494387 -56148 -741183 -661813 21364 -977099 428505
4 7 2 1 6 8
Output
-2380095
Judge Output
-2380095
Checker Message
1 number(s): "-2380095"
Test Case #37
0 ms
808 KB
Accepted
Input
14 2
12 12 8 4 11 3 7 11 2 4 3 6 2 10
257678 640382 -540258 -783943 -157499 -219622 -290176 477029 -728995 335055 138772 919589 -188870 -519874
2 3
Output
-2700242
Judge Output
-2700242
Checker Message
1 number(s): "-2700242"
Test Case #38
0 ms
808 KB
Accepted
Input
18 5
3 10 9 1 8 17 12 3 14 2 10 4 7 9 13 8 3 8
834621 -382818 213234 600924 -812977 516986 -252603 -245585 -828411 667038 806509 -534627 610660 338403 -355266 891784 424920 -808201
2 4 9 8 3
Output
-3685861
Judge Output
-3685861
Checker Message
1 number(s): "-3685861"
Test Case #39
0 ms
808 KB
Accepted
Input
6 3
3 5 1 2 2 1
530628 690590 681144 351497 885372 -438285
5 2 1
Output
0
Judge Output
0
Checker Message
1 number(s): "0"
Test Case #40
0 ms
832 KB
Accepted
Input
14 6
9 11 6 2 9 11 13 11 3 7 12 10 9 4
-654939 796367 -282421 -851761 96037 -572846 -180032 893847 547789 -620561 44658 746038 -707627 582536
2 13 11 3 12 10
Output
-2838394
Judge Output
-2838394
Checker Message
1 number(s): "-2838394"
Test Case #41
0 ms
808 KB
Accepted
Input
14 3
12 1 12 9 12 1 3 2 11 9 4 9 6 9
431195 -25783 -139065 157106 564851 913134 -787382 47655 -249314 3695 686913 -984118 -890999 -631481
12 9 6
Output
-2817143
Judge Output
-2817143
Checker Message
1 number(s): "-2817143"
Test Case #42
0 ms
816 KB
Accepted
Input
2 1
2 2
4973 -348485
2
Output
-348485
Judge Output
-348485
Checker Message
1 number(s): "-348485"
Test Case #43
0 ms
820 KB
Accepted
Input
6 1
4 6 3 3 5 1
784610 -479599 -843277 96625 163152 -464136
1
Output
-1322876
Judge Output
-1322876
Checker Message
1 number(s): "-1322876"
Test Case #44
0 ms
820 KB
Accepted
Input
20 8
1 20 10 14 14 10 4 20 16 1 10 18 18 13 19 20 1 19 20 12
-712769 288163 52619 -174585 -93220 522286 -265468 -758304 258336 -374344 -401971 -87211 -404099 785886 180823 -477461 391584 897377 -538760 14176
14 10 4 16 13 1 19 12
Output
-3929504
Judge Output
-3929504
Checker Message
1 number(s): "-3929504"
Test Case #45
0 ms
952 KB
Accepted
Input
9 4
9 6 6 4 9 4 6 6 3
150468 74576 896680 -827807 -168774 86661 -397858 -308005 -475742
6 9 4 3
Output
-1533670
Judge Output
-1533670
Checker Message
1 number(s): "-1533670"
Test Case #46
0 ms
820 KB
Accepted
Input
9 3
5 8 8 3 1 5 8 2 4
-545404 -396590 650890 135365 443638 -135237 454699 421887 555793
8 3 2
Output
-1077231
Judge Output
-1077231
Checker Message
1 number(s): "-1077231"
Test Case #47
0 ms
824 KB
Accepted
Input
17 2
7 14 14 16 8 12 17 11 4 8 1 4 15 1 11 15 7
-625951 651859 961524 -212115 206780 -510706 -467472 238029 -873525 -162018 -590564 203349 -577916 -921908 -368859 -676625 -823216
15 7
Output
-5409743
Judge Output
-5409743
Checker Message
1 number(s): "-5409743"
Test Case #48
0 ms
824 KB
Accepted
Input
1 1
1
-335323
1
Output
0
Judge Output
0
Checker Message
1 number(s): "0"
Test Case #49
0 ms
824 KB
Accepted
Input
9 2
7 1 2 1 8 8 8 8 7
-82453 789031 -409476 956318 351686 -135836 408201 -176952 -833624
8 7
Output
-804717
Judge Output
-804717
Checker Message
1 number(s): "-804717"
Test Case #50
0 ms
824 KB
Accepted
Input
13 5
1 4 7 2 2 6 9 1 11 8 9 8 10
793926 -368838 -856091 999137 289720 395397 651995 205270 -536639 -642685 -874043 698805 -253274
2 6 8 9 10
Output
-1761568
Judge Output
-1761568
Checker Message
1 number(s): "-1761568"
Test Case #51
0 ms
824 KB
Accepted
Input
17 1
6 17 11 6 17 10 4 17 6 16 17 1 8 1 9 10 17
-957441 -479302 -303791 -212161 900098 -853329 -74487 659602 796962 99001 643127 84217 678605 364554 807249 -223343 309060
17
Output
-3103854
Judge Output
-3103854
Checker Message
1 number(s): "-3103854"
Test Case #52
0 ms
824 KB
Accepted
Input
5 2
3 3 3 1 2
-457721 -993273 -686953 -974099 -399460
3 2
Output
-2654325
Judge Output
-2654325
Checker Message
1 number(s): "-2654325"
Test Case #53
0 ms
824 KB
Accepted
Input
9 3
2 8 2 1 9 9 1 5 9
571379 770197 749418 -937515 -808882 863188 20693 -166623 -471032
8 9 5
Output
-2217429
Judge Output
-2217429
Checker Message
1 number(s): "-2217429"
Test Case #54
0 ms
824 KB
Accepted
Input
15 4
8 6 3 2 7 5 15 13 2 15 7 8 10 12 15
46765 807973 376917 656773 -222235 535371 -605201 820909 14396 -39021 227486 -250655 232459 308912 561024
2 10 12 15
Output
-1117112
Judge Output
-1117112
Checker Message
1 number(s): "-1117112"
Test Case #55
0 ms
828 KB
Accepted
Input
139 24
86 111 16 73 13 27 42 108 66 37 59 10 109 10 56 58 108 44 66 25 130 73 8 103 94 113 74 124 97 125 65 35 120 29 93 20 138 10 7 42 123 7 113 87 110 18 106 84 126 16 81 64 132 108 112 65 87 70 38 37 50 72 66 115 98 57 136 2 94 40 119 125 66 133 ...
Output
-29850204
Judge Output
-29850204
Checker Message
1 number(s): "-29850204"
Test Case #56
0 ms
828 KB
Accepted
Input
859 214
97 433 646 815 250 397 685 226 275 392 641 586 375 12 200 260 218 181 683 548 748 43 205 293 773 595 274 326 726 304 246 616 318 477 19 528 121 633 378 510 248 632 469 349 162 611 654 400 422 777 462 319 789 731 831 780 348 804 256 729 344 2...
Output
-171918350
Judge Output
-171918350
Checker Message
1 number(s): "-171918350"
Test Case #57
0 ms
832 KB
Accepted
Input
859 214
97 433 646 815 250 397 685 226 275 392 641 586 375 12 200 260 218 181 683 548 748 43 205 293 773 595 274 326 726 304 246 616 318 477 19 528 121 633 378 510 248 632 469 349 162 611 654 400 422 777 462 319 789 731 831 780 348 804 256 729 344 2...
Output
-171918350
Judge Output
-171918350
Checker Message
1 number(s): "-171918350"
Test Case #58
0 ms
828 KB
Accepted
Input
987 328
765 198 450 848 866 320 830 603 105 196 815 54 536 385 412 392 837 901 519 551 533 31 620 444 195 357 751 130 485 446 92 927 580 914 65 453 133 780 259 108 476 499 363 418 340 64 62 936 16 360 150 629 774 882 411 306 239 218 269 883 132 470 ...
Output
-157733882
Judge Output
-157733882
Checker Message
1 number(s): "-157733882"
Test Case #59
0 ms
836 KB
Accepted
Input
411 88
361 398 160 346 20 138 119 67 393 81 349 37 292 67 281 54 206 117 111 80 324 348 131 191 255 61 181 96 194 265 129 331 299 284 147 356 52 8 308 136 303 152 223 395 279 266 356 252 317 332 210 297 186 284 11 117 76 387 103 398 64 339 217 92 2...
Output
-77173418
Judge Output
-77173418
Checker Message
1 number(s): "-77173418"
Test Case #60
0 ms
856 KB
Accepted
Input
539 46
286 92 272 412 432 87 427 55 249 243 412 246 39 68 31 251 379 89 432 107 73 204 482 454 41 364 442 530 349 293 451 97 457 514 157 205 375 330 401 365 155 33 143 5 355 492 15 302 466 260 394 344 30 279 526 143 422 440 294 25 149 350 522 63 211...
Output
-117160201
Judge Output
-117160201
Checker Message
1 number(s): "-117160201"
Test Case #61
0 ms
836 KB
Accepted
Input
259 47
6 57 49 41 29 53 157 170 236 142 72 221 4 108 111 128 105 182 166 247 162 37 45 177 123 96 169 230 176 53 88 250 75 15 41 174 9 105 5 229 135 132 239 167 153 127 77 10 205 228 194 61 57 245 243 250 220 137 19 52 17 62 131 166 133 233 231 160 ...
Output
-47380304
Judge Output
-47380304
Checker Message
1 number(s): "-47380304"
Test Case #62
0 ms
836 KB
Accepted
Input
387 3
340 236 238 313 175 306 246 233 376 5 291 20 68 10 362 182 255 289 288 187 203 158 90 160 294 230 19 49 319 275 92 76 368 254 235 170 279 141 162 299 280 105 278 165 178 187 245 256 387 1 210 115 2 129 383 110 203 145 24 378 29 335 369 204 236...
Output
-101504484
Judge Output
-101504484
Checker Message
1 number(s): "-101504484"
Test Case #63
0 ms
836 KB
Accepted
Input
515 97
111 48 507 509 303 154 450 424 437 30 385 114 111 7 203 469 25 269 108 133 133 236 109 190 270 149 376 27 252 249 271 49 134 451 358 508 187 265 247 245 170 168 138 69 349 323 304 426 349 126 264 210 389 263 64 171 356 294 231 205 134 148 383...
Output
-107869947
Judge Output
-107869947
Checker Message
1 number(s): "-107869947"
Test Case #64
0 ms
840 KB
Accepted
Input
939 271
107 529 578 937 353 668 336 407 606 504 554 4 314 625 4 619 166 154 385 646 791 62 564 797 612 344 875 809 711 62 664 678 100 19 543 511 9 714 635 255 286 887 30 761 224 857 552 864 31 75 54 332 322 507 938 347 818 855 101 338 94 506 533 938...
Output
-173584641
Judge Output
-173584641
Checker Message
1 number(s): "-173584641"
Test Case #65
0 ms
840 KB
Accepted
Input
518 121
37 97 47 278 17 467 158 66 483 351 83 123 285 219 513 187 380 75 304 352 367 144 264 190 384 115 307 92 11 158 473 157 120 286 140 144 325 4 27 206 167 269 45 360 390 259 320 101 123 483 150 233 449 118 300 165 199 50 32 188 150 276 144 466 ...
Output
-105539905
Judge Output
-105539905
Checker Message
1 number(s): "-105539905"
Test Case #66
0 ms
836 KB
Accepted
Input
646 80
132 569 125 160 100 383 456 328 363 153 461 180 196 338 77 91 370 611 55 198 188 639 383 36 101 236 356 108 203 446 94 57 517 289 384 352 538 300 125 216 496 455 252 372 420 321 506 619 1 525 259 181 381 130 281 452 204 76 387 38 408 492 64 ...
Output
-124100333
Judge Output
-124100333
Checker Message
1 number(s): "-124100333"
Test Case #67
0 ms
864 KB
Accepted
Input
70 26
54 37 62 1 46 13 17 38 47 28 15 63 5 61 34 49 66 32 59 3 41 58 28 23 62 41 64 20 5 14 41 10 37 51 32 65 46 61 8 15 19 16 44 31 42 19 46 66 25 26 58 60 5 19 18 69 53 20 40 45 27 24 41 32 23 57 56 62 10 49
281986 -519003 -478298 856602 -100760 9...
Output
-11426144
Judge Output
-11426144
Checker Message
1 number(s): "-11426144"
Test Case #68
0 ms
840 KB
Accepted
Input
494 83
226 314 420 386 475 253 37 307 308 332 21 44 486 164 98 413 236 193 118 301 169 295 167 293 55 431 394 181 357 419 112 388 14 459 388 104 279 396 413 111 38 402 57 203 385 57 488 147 219 362 283 296 185 127 113 458 180 396 62 120 416 444 292 ...
Output
-110813807
Judge Output
-110813807
Checker Message
1 number(s): "-110813807"
Test Case #69
0 ms
844 KB
Accepted
Input
918 369
849 604 207 73 224 701 714 111 212 848 82 148 637 27 607 170 237 674 274 413 844 889 726 81 307 426 101 173 437 563 781 790 611 351 317 485 591 188 666 500 236 507 734 91 721 773 492 351 614 172 779 760 511 617 732 753 781 686 489 501 393 8...
Output
-145554008
Judge Output
-145554008
Checker Message
1 number(s): "-145554008"
Test Case #70
0 ms
848 KB
Accepted
Input
46 5
5 5 1 20 10 15 12 23 39 5 46 7 20 10 15 14 13 10 29 4 9 24 11 23 4 9 17 45 35 14 41 11 36 37 45 26 43 35 45 10 15 23 30 6 6 9
-53781 -788924 675503 788830 -375434 874291 777837 -935925 790321 -389815 -473105 -6476 -525259 619120 -365448 -659904...
Output
-12655369
Judge Output
-12655369
Checker Message
1 number(s): "-12655369"
Test Case #71
0 ms
844 KB
Accepted
Input
174 56
173 165 110 40 113 151 21 75 97 107 112 70 65 106 42 108 93 77 171 34 77 151 102 32 59 136 97 67 141 84 6 41 12 105 53 111 42 94 165 31 160 60 107 106 88 83 88 29 56 152 95 107 63 2 103 111 158 117 79 131 27 41 60 130 145 124 100 28 86 101 74...
Output
-28758516
Judge Output
-28758516
Checker Message
1 number(s): "-28758516"
Test Case #72
0 ms
844 KB
Accepted
Input
894 71
506 465 212 611 108 353 761 688 789 91 644 367 132 73 160 850 571 652 156 428 776 468 707 210 770 207 706 712 406 572 763 793 197 822 887 522 604 728 268 315 3 798 24 795 865 311 576 43 56 789 692 721 791 760 508 158 273 165 139 476 551 415 2...
Output
-202938268
Judge Output
-202938268
Checker Message
1 number(s): "-202938268"
Test Case #73
0 ms
844 KB
Accepted
Input
22 7
22 2 4 4 1 19 10 22 16 14 9 9 15 14 14 15 3 9 10 14 3 7
988227 -89577 67202 462973 -942079 -823339 416623 -449443 221302 -916804 192018 -594465 -817259 113453 -977779 51831 990690 -525040 102702 335766 -486604 -786724
1 22 15 10 14 3 7
Output
-4744263
Judge Output
-4744263
Checker Message
1 number(s): "-4744263"
Test Case #74
0 ms
976 KB
Accepted
Input
446 134
274 164 35 61 113 341 136 140 24 118 143 330 118 363 291 163 277 39 95 181 15 415 101 58 98 419 376 88 174 151 251 40 255 374 214 246 189 350 152 110 189 225 445 161 64 195 288 57 83 133 341 136 57 155 406 250 23 60 87 387 175 383 63 232 399...
Output
-78213388
Judge Output
-78213388
Checker Message
1 number(s): "-78213388"
Test Case #75
0 ms
848 KB
Accepted
Input
440 72
281 300 290 294 434 430 4 400 356 301 350 438 258 173 419 180 281 339 420 172 59 377 219 394 5 16 66 406 360 393 402 254 227 59 76 177 247 313 36 229 226 385 376 113 133 229 429 68 206 230 211 340 247 84 52 296 53 71 89 127 305 354 269 399 2...
Output
-96927653
Judge Output
-96927653
Checker Message
1 number(s): "-96927653"
Test Case #76
0 ms
868 KB
Accepted
Input
569 160
237 294 397 197 200 247 116 545 143 176 470 32 56 278 114 442 432 144 448 414 456 552 367 210 5 101 53 215 508 364 87 457 384 117 312 442 398 445 87 6 301 476 45 155 284 163 95 448 407 351 123 68 491 85 400 168 197 145 110 10 175 392 402 249...
Output
-95489543
Judge Output
-95489543
Checker Message
1 number(s): "-95489543"
Test Case #77
0 ms
848 KB
Accepted
Input
289 80
20 129 189 85 191 42 33 197 29 287 252 25 144 259 194 72 277 22 46 84 87 72 289 217 137 109 259 10 8 19 159 63 134 133 111 262 16 167 75 147 79 260 160 33 237 212 196 243 6 102 184 137 236 50 170 242 281 16 287 68 258 148 7 244 235 120 272 1...
Output
-51663964
Judge Output
-51663964
Checker Message
1 number(s): "-51663964"
Test Case #78
0 ms
856 KB
Accepted
Input
417 73
384 256 331 329 50 327 168 142 169 80 94 232 212 334 114 247 324 8 268 270 68 56 199 202 281 215 365 167 138 71 9 243 407 237 106 45 258 56 412 28 263 6 143 37 67 78 400 13 32 62 253 375 104 183 73 77 306 379 55 208 227 128 216 128 68 33 102 ...
Output
-85650065
Judge Output
-85650065
Checker Message
1 number(s): "-85650065"
Test Case #79
0 ms
860 KB
Accepted
Input
841 184
97 102 14 292 716 198 345 683 58 644 551 484 823 251 106 191 602 260 50 240 166 225 522 337 79 445 345 562 349 251 764 792 613 811 610 11 101 179 9 35 795 609 93 826 606 106 804 15 734 521 596 214 667 71 693 93 501 466 193 323 135 2 503 267 ...
Output
-167179255
Judge Output
-167179255
Checker Message
1 number(s): "-167179255"
Test Case #80
0 ms
856 KB
Accepted
Input
969 232
211 181 161 661 935 275 155 149 940 743 774 70 126 872 928 115 729 509 503 672 420 621 47 211 445 954 920 533 957 169 932 202 329 77 791 181 155 957 419 677 959 251 525 567 148 613 233 875 169 91 721 54 853 325 280 406 849 711 263 327 243 9...
Output
-193931602
Judge Output
-193931602
Checker Message
1 number(s): "-193931602"