CT55570

Pavel and the Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Pavel found an old ledger of panels in the mint attic at the clockwork quarter of Gearford. 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 <= 3146; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1239 494 -594729 -795657 -519292 -559159 -920192 -977029 -325536 -376073 -427335 -857832 -791203 -6570 -81153 -601229 -498274 -364256 -858483 -276050 -605816 -1029 -824663 -433040 -888055 -555245 -97142 -954354 -181471 -256429 -938658 -573840 -906347 -577424 -935966 -252491 -698626 -781302 -274742 -713994 -23543 -874959 -317668 -865865 -700844 -680887 -117739 -142878 -24993 -302638 -561334 -467847 -193992 -178601 -415880 -360938 -452858 -416000 -394687 -290912 -734119 -732790 -520240 -634184 -638404 -108111 -789495 -233700 -299812 -878964 -892819 -588303 -55174 -222130 -734012 -942183 -696768 -705957 -890110 -908292 -829871 -654733 -422857 -278922 -654721 -867044 -950333 -920565 -908585 -297404 -197975 -312940 -788487 -440989 -137556 -925747 -433152 -142574 -929816 -936254 -385333 -958984 …
Output: -228670113

Example 2:

Input: 259 197 -919130 -610496 -402996 -502196 -611957 -341465 -346234 -961385 -74211 -12375 -362323 -990840 -249755 -319083 -245562 -51785 -186524 -439011 -314609 -72423 -804142 -132788 -684154 -391504 -441001 -36042 -764850 -387327 -803880 -284326 -278726 -8697 -32844 -600609 -945775 -573263 -605602 -468678 -79377 -583637 -718208 -811228 -78209 -854874 -988252 -536493 -546947 -961442 -826280 -974339 -92447 -820221 -168331 -882453 -104708 -158418 -624500 -331697 -592096 -417915 -337366 -502939 -785245 -255609 -176196 -7864 -65848 -900200 -901597 -791419 -942408 -472125 -406045 -996547 -908315 -647767 -666195 -738191 -407763 -972494 -113772 -648822 -676760 -183332 -669818 -520004 -188207 -79000 -570402 -976433 -844549 -548479 -343406 -539041 -336329 -67317 -872483 -679628 -1100 -599758 -803659 -4…
Output: -95595495

Example 3:

Input: 895 600 -317817 -730024 -542009 -434307 -39533 -346633 -934275 -975237 -181310 -489300 -877509 -301627 -929454 -70091 -876498 -177104 -116653 -642065 -117448 -335401 -657356 -413388 -780597 -29199 -90610 -231116 -80746 -722609 -547640 -777681 -35621 -526720 -191109 -679451 -311874 -382527 -73799 -85919 -975048 -511874 -5041 -120240 -307990 -710581 -145299 -705341 -107972 -933483 -84764 -566041 -265533 -515087 -274901 -389399 -935685 -443621 -297250 -463886 -227312 -443710 -431260 -249614 -59533 -73486 -350008 -661298 -909630 -692898 -187304 -515544 -794304 -498758 -760348 -436525 -451002 -773377 -478840 -944075 -698974 -409146 -892667 -301907 -584474 -957527 -875363 -54130 -742486 -210108 -335553 -412287 -686520 -846721 -950278 -769444 -34617 -821326 -978938 -810457 -328786 -538977 -856525…
Output: -290647327

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.