CT40825

Ivan's Scarlet Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Ivan runs the observatory at the dune sea of Caravanrest. Today the books show a list of panels, and the numbers must be worked out before sundown. 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 <= 1395; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1239 451 -323831 -949113 -598572 -555543 -463657 -170254 -976181 -276729 -489151 -938353 -639875 -861985 -182851 -613982 -146859 -568959 -996749 -196699 -608831 -795049 -751772 -748668 -197526 -881964 -131997 -145496 -977890 -316664 -128995 -182822 -561576 -890611 -658307 -595367 -810610 -289272 -454309 -697920 -394377 -722459 -165364 -178313 -812759 -788945 -284678 -132013 -767900 -927601 -195773 -423717 -795971 -317586 -382575 -154463 -377858 -327711 -378206 -130645 -353183 -508827 -129971 -752617 -634168 -60923 -445625 -95318 -864294 -493056 -97092 -947465 -636136 -138300 -391800 -758032 -70005 -745614 -101233 -451337 -315734 -522017 -921099 -483775 -92981 -238092 -541266 -480502 -380381 -476867 -399528 -121380 -757269 -610608 -955475 -901956 -798161 -78384 -425136 -413988 -701917 -2301…
Output: -210369369

Example 2:

Input: 436 62 -37822 -255043 -687812 -79357 -411386 -873364 -601817 -791838 -641273 -492268 -61057 -553709 -167493 -732850 -381132 -546433 -123452 -860647 -314375 -519640 -847692 -464067 -715652 -872442 -391198 -954203 -8010 -747607 -615593 -924984 -432218 -223334 -312152 -265692 -858709 -270236 -65349 -929855 -271948 -548146 -649096 -418608 -548564 -693917 -748997 -765623 -16428 -203439 -357698 -692544 -381821 -320198 -614807 -921137 -689703 -636319 -996076 -95203 -494512 -72859 -953598 -362887 -330360 -763011 -411015 -227930 -301374 -680866 -697786 -844878 -598734 -796752 -40534 -866365 -931838 -668814 -311629 -531314 -906098 -692453 -112996 -761301 -256721 -583334 -939271 -261882 -472962 -321063 -3767 -469249 -4908 -76625 -626074 -727784 -127160 -583521 -877594 -888147 -576210 -241919 -862362 …
Output: -27135095

Example 3:

Input: 851 810 -891863 -679343 -953532 -399530 -719696 -909022 -996134 -298584 -76305 -937766 -98481 -136417 -660842 -891571 -970379 -302525 -130753 -897156 -715660 -99118 -204276 -385687 -99142 -858512 -304022 -104262 -436661 -788931 -620743 -139260 -573464 -673981 -792289 -683411 -988333 -419603 -888395 -440086 -104137 -960672 -603948 -471283 -266096 -795413 -581514 -336294 -610584 -50020 -311452 -547704 -546236 -745440 -815042 -772028 -310279 -216283 -820583 -860525 -294123 -141655 -463865 -307344 -287242 -548941 -716079 -468468 -736567 -794801 -175596 -197048 -301466 -656416 -880848 -813110 -655089 -96213 -709381 -27190 -889461 -291094 -91752 -194161 -849976 -911013 -182309 -794453 -214706 -444589 -360458 -373150 -740048 -558451 -330751 -952931 -128981 -47743 -702504 -358638 -465248 -74123 -7…
Output: -398985443

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Ivan's Scarlet Ledger - MEDIUM Coding Problem | CodeTikki