CT37598

The Fixed Window Peak of Luminar

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Viktor found an old ledger of segments in the workshop attic at the crystal caves of Luminar. 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 <= 2961; -1000000 <= a[i] <= 1000.

Example 1:

Input: 2111 382 -798970 -861993 -359132 -99035 -810196 -834570 -695179 -444754 -117345 -375157 -783518 -185407 -94870 -673757 -215080 -932796 -782304 -849049 -661 -45350 -678519 -324697 -334845 -811560 -463301 -671536 -16656 -673709 -190810 -34181 -93671 -229290 -909850 -719595 -576827 -311115 -672910 -472053 -135065 -538711 -45812 -448677 -630690 -807031 -588993 -521021 -850908 -282045 -455080 -644530 -484921 -201242 -356227 -823614 -263895 -98629 -548922 -269548 -424002 -53389 -866335 -842467 -744968 -304080 -346357 -740576 -169326 -199359 -101898 -733705 -588206 -851965 -639971 -560922 -385470 -776736 -873086 -932131 -533326 -335367 -519187 -540485 -121631 -342581 -282238 -957685 -953616 -357700 -688032 -52446 -765054 -258729 -659775 -994764 -447597 -668359 -615554 -775959 -587305 -104964 -131…
Output: -184055515

Example 2:

Input: 702 580 -181085 -321073 -586143 -356440 -349876 -137304 -310059 -497975 -249393 -786423 -442386 -816268 -648706 -497782 -73384 -947799 -509560 -613593 -381775 -690123 -671059 -982393 -791975 -123364 -523242 -953916 -582975 -831903 -37681 -788527 -342845 -378776 -155927 -333480 -875938 -334321 -897223 -382539 -536682 -949310 -271358 -394851 -346527 -284856 -150734 -217931 -410466 -927139 -161435 -245842 -245595 -9181 -416920 -749120 -153540 -766726 -626980 -828509 -231250 -532595 -184605 -780627 -538550 -407194 -251801 -48763 -567312 -199582 -78051 -79173 -967362 -78214 -869421 -70131 -934525 -603487 -386192 -690553 -467368 -351031 -422635 -908325 -165085 -120462 -932684 -223732 -188443 -480119 -53740 -567361 -362813 -288300 -214580 -261164 -766930 -928320 -751425 -224792 -505720 -145766 -3…
Output: -284754465

Example 3:

Input: 2717 1788 -168464 -780806 -779342 -77993 -398835 -668187 -659246 -651342 -312792 -254475 -975006 -661204 -637270 -317261 -67132 -517904 -453897 -618824 -118107 -197428 -808540 -325889 -286551 -893929 -682194 -840811 -553892 -4813 -132466 -298522 -839691 -403149 -921907 -698442 -275520 -224754 -583036 -69352 -538318 -169051 -126610 -497980 -277483 -143367 -202757 -235128 -609249 -393820 -940887 -624857 -546823 -133332 -583721 -851985 -367988 -287058 -953923 -796991 -846243 -701515 -316789 -387826 -475414 -740276 -490157 -892635 -851853 -368092 -944565 -36061 -288094 -472585 -530922 -599710 -870318 -672575 -796574 -168590 -29939 -36016 -118763 -318310 -214704 -146276 -969380 -948952 -475721 -532322 -890791 -930202 -337342 -2738 -397026 -173179 -335642 -415141 -508241 -539971 -302736 -837188 …
Output: -889245995

Constraints:

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

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