CT43589

Amara's Fixed Window Peak Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the otter slides of Sleekwater, someone must tally the donation drive. This year the task falls to Amara, armed only with the stretches register. 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 <= 2867; -1000000 <= a[i] <= 1000.

Example 1:

Input: 41 38 -371614 -868050 -436607 -190572 -251177 -341209 -863452 -405281 -839578 -648547 -891651 -749035 -705965 -917411 -919856 -761257 -373292 -698819 -881987 -129293 -893093 -760214 -734844 -408014 -823972 -261763 -795700 -275871 -652711 -658516 -853178 -552745 -490770 -48381 -704865 -493225 -50154 -455569 -721956 -462014 -326223
Output: -21992160

Example 2:

Input: 2430 2109 -413117 -516730 -297412 -772670 -16356 -399771 -327380 -907985 -951869 -135485 -906670 -819563 -649334 -650470 -718961 -621803 -945550 -448001 -68564 -379575 -752846 -582246 -180236 -226120 -335967 -982766 -991497 -528631 -327433 -956243 -226358 -157696 -87155 -132442 -178245 -541405 -830767 -423646 -421999 -530429 -217200 -496356 -41600 -476290 -111198 -349808 -283506 -562537 -535466 -338605 -237214 -753647 -910223 -768509 -743699 -171230 -710390 -272925 -833804 -552034 -443531 -986263 -174951 -167177 -944044 -240303 -994073 -869813 -981817 -51091 -557995 -756110 -715834 -21445 -266631 -803584 -205147 -680217 -580084 -509657 -458656 -6449 -156114 -867157 -634529 -22894 -869355 -669806 -260159 -350086 -942446 -385458 -180143 -37415 -424314 -712888 -874403 -49460 -656979 -2822 -86…
Output: -1031093310

Example 3:

Input: 92 64 -659698 -13151 -936951 -149019 -670164 -42096 -254154 -109955 -22068 -818247 -958491 -975998 -30307 -468909 -274692 -403841 -10039 -826063 -999765 -755956 -358999 -502458 -816749 -651399 -84886 -690589 -75314 -787884 -113931 -206119 -171347 -650509 -528957 -73728 -231045 -5227 -704066 -473994 -382614 -19914 -212917 -143536 -294680 -671988 -193045 -383907 -661842 -724880 -413625 -241789 -291836 -473656 -513179 -6454 -812724 -751080 -532692 -833929 -98424 -979992 -652596 -83161 -607920 -683935 -984937 -277963 -415714 -776697 -414192 -847782 -591887 -530204 -369283 -787076 -331752 -603094 -822966 -912525 -549757 -700162 -954389 -831540 -446136 -486731 -394386 -536029 -380701 -871604 -503846 -308363 -946982 -140215
Output: -28173080

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Amara's Fixed Window Peak Ledger - MEDIUM Coding Problem | CodeTikki