CT43856

Galen and the Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Every season at the lotus ponds of Tranquil Basin, someone must prove the quality of the harvest. This year the task falls to Galen, armed only with the scrolls 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 <= 1884; -1000000 <= a[i] <= 1000.

Example 1:

Input: 374 245 -741818 -398828 -42190 -752332 -886903 -792945 -183558 -904500 -255842 -260429 -703768 -486844 -34510 -652806 -657030 -997038 -22905 -942067 -729978 -984214 -908336 -497390 -640732 -323516 -609737 -308595 -622301 -972240 -739613 -278176 -404718 -389964 -275330 -185287 -180006 -37963 -893121 -525232 -530148 -510645 -549663 -392262 -818229 -567643 -466629 -964583 -100488 -705672 -21390 -480809 -127915 -286864 -812989 -931270 -136204 -893286 -473729 -495774 -510973 -185302 -220114 -4133 262 -264022 -580510 -401714 -149017 -369305 -829712 -817493 -654948 -878222 -496752 -551514 -106253 -399787 -246008 -146438 -252394 -796004 -923653 -777464 -312623 -933581 -594808 -522086 -10329 -695473 -512546 -146246 -877310 -658581 -319528 -896625 -821212 -615819 -427195 -775675 -979814 -516912 -356…
Output: -121500270

Example 2:

Input: 1588 233 -359384 -826253 -249245 -580442 -767900 -6125 -229095 -368729 -236965 -694019 -410983 -917616 -114580 -241573 -113753 -544246 -893009 -224679 -684857 -769559 -57989 -470666 -961730 -468339 -308942 -675775 -81369 -353388 -816505 -427888 -316185 -761155 -560493 -500310 -227506 -263723 -639334 -5057 -375860 -131170 -16721 -59206 -140162 -203862 -681314 -554772 -47215 -494769 -38728 -799672 -952087 -426010 -26755 -754011 -947548 -542728 -191894 -383896 -784534 -309923 -525499 -764221 -916244 -268497 -20369 -205273 -302203 -693725 -957462 -630893 -20069 -111424 -118838 -159960 -39816 -511254 -133500 -157637 -265745 -317751 -84224 -702365 -757829 -561390 -70689 -308154 -487050 -343674 -976695 -764017 -705823 -945622 -524404 -739902 -924239 -556386 -869623 -432421 -951572 -964707 -941009…
Output: -104218997

Example 3:

Input: 1686 1052 -675195 -867663 -450313 -382297 -77796 -133252 -136397 -102586 -344892 -730941 -574838 -770624 -183632 -965005 -425259 -474877 -828011 -652345 -969193 -79431 -146948 -762544 -41140 -250305 -338028 -107948 -928836 -390206 -958616 -786197 -927469 -856963 -567967 -211372 -826417 -841068 -693050 -49821 -870557 -728880 -993954 -335954 -937196 -217056 -578862 -550299 -182282 -677888 -411100 -228777 -903857 -132562 -341991 -272212 -797904 -282794 -853093 -129183 -116870 -964183 -212556 -878120 -275359 -262960 -876553 -453484 -66951 -837509 -960179 -856651 -156236 -851503 -638489 -557423 -575329 -903646 -48230 -664055 -185912 -179881 -600872 -84863 -832797 -910515 -337465 -719861 -940517 -109736 -142241 -183879 -350156 -776047 -580358 -492420 -148382 -582797 -321028 -319239 -582417 -2426…
Output: -529905726

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Galen and the Fixed Window Peak - MEDIUM Coding Problem | CodeTikki