CT44739

The Amber ribbons of Archivist

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Archivist found an old ledger of ribbons in the apiary attic at the acacia flats of Thornveld. The margin notes pose a precise question. Task: Print the maximum sum of any contiguous subarray of length exactly k. Input format: First line: n and k. Second line: n integers. Output format: Print the maximum window sum. Constraints: 1 <= k <= n <= 3133; -1000000 <= a[i] <= 1000.

Example 1:

Input: 2361 1555 -693254 -204692 -184390 -409177 -916472 -618954 -951971 -419030 -592166 -45887 -567121 -602005 -770964 -705058 -948223 -613598 -378241 -384037 -871649 -517907 -730811 -748451 -96947 -666951 -27323 -375665 -781381 -626133 -542111 -496302 -807288 -294651 -480491 -632127 -452141 -733612 -816808 -772193 -151831 -702086 -904916 -859913 -429341 -995363 -570808 -521191 -228789 -963215 -881758 -360459 -926758 -943301 -914283 -388991 -562979 -359125 -718323 -940434 -945249 -603422 -199805 -713963 -373884 -269447 -262703 -251836 -411901 -663554 -499226 -481497 -203341 -294235 -884914 -70795 -220717 -798375 -722069 -89894 -249544 -504872 -135931 -85865 -722837 -660790 -348883 -500111 366 -42659 -901386 -67366 -989048 -756087 -178167 -770541 -990565 -373517 -101625 -990198 -989067 -428696 -3…
Output: -777505325

Example 2:

Input: 1818 1722 -968894 -611865 -608486 -805887 -151446 -31539 -268699 -886129 -755245 -524252 -684358 -89443 -300922 -908731 -189853 -181055 -147821 -193517 -750985 -358441 -259726 -756201 -652605 -231771 -245455 -800448 -897478 -41504 -290974 -156273 -385977 -65174 -393246 -356807 -947966 -981386 -105408 -423162 -610810 -311926 -381848 -564463 -194484 -97354 -373928 -2294 -72694 -626529 -278397 -254961 -467838 -709638 -562173 -721352 -594704 -875515 -674742 -952644 -511448 -238054 -90310 -971297 -930430 -420921 -430899 -739108 -14771 -988424 -187153 -648234 -711882 -733726 -54594 -244207 -361316 -844103 -589942 -91009 -631113 -714224 -194364 -805035 -192968 -79461 -625922 -494088 -41839 -251984 -56479 -553313 -176334 -764055 -555283 -21688 -224387 -659064 -386548 -415133 -839300 -778709 -13096…
Output: -848162625

Example 3:

Input: 2148 1928 -558238 -108721 -469977 -757747 -299582 -412522 -114935 -754558 -735124 -601858 -669452 -533186 -709082 113 -624251 -192199 -87079 -812384 -277883 -631127 -809156 -706264 -398620 -691361 -556766 -641770 -20309 -983730 -607748 -67223 -764543 -39570 -818712 -811784 -495387 -766967 -878940 -724766 -64394 -201517 -334779 -171956 -718716 -976459 -555695 -485670 -660762 -978144 -396028 -647090 -762349 -486222 -158970 -465847 -344532 -675936 -845463 -902479 -286466 -52696 -758662 -779447 -773412 -67391 -760092 -48578 -695866 -96691 -436323 -641350 -802184 -86398 -470622 -608560 -748716 -525454 -745061 -872075 -616258 -451730 -789766 -42146 -522748 -977994 -488577 -848170 -729145 -125235 -81008 -15564 -371694 -881578 -779066 -812923 -665290 -63759 -153284 -321648 -186021 -653851 -534514 …
Output: -959967495

Constraints:

1 <= k <= n <= 3133; -1000000 <= a[i] <= 1000.

Loading...
Test Cases:No test cases
No test cases available.
The Amber ribbons of Archivist - MEDIUM Coding Problem | CodeTikki