CT40704

Hope's Granite Ledger

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the heron rookery of Longlegs opens only for a perfect tally of segments. Hope means to find out. 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 <= 2592; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1524 1054 -154661 -818626 -170529 -650761 -575026 -474264 -543610 -773343 -887602 -539999 -436840 -799205 -534859 -328301 -415407 -775398 -110650 -655236 -813175 -155780 -87115 -107101 -131036 -800044 -81514 -439613 -709686 -8994 -307243 -793739 -346744 -318872 -658002 -60270 -348441 -407101 -389424 -678240 -657234 -48938 -360379 -754939 -653510 -214325 -578926 -229173 -112770 -202605 -935337 -642055 -455815 -895627 -814824 -468088 -278234 -558931 -318451 -627497 -665998 -516850 -431847 -448792 -962337 -214815 -989993 -203532 -287244 -408653 -922120 -561704 -66097 -572046 -938261 -990440 -190706 -289104 -97822 -620303 -671037 -239919 -436023 -341943 -212994 -954619 -102012 -298201 -764185 -997143 -896933 -183898 -915581 -629220 -573420 -229598 -173732 -575690 -28696 -837118 -300242 -824529…
Output: -529607367

Example 2:

Input: 1515 818 -365092 -633195 -701294 -412897 -52661 -59137 -800648 -423447 -678869 -692335 -747888 -371223 -630986 -711739 -395280 -807341 -455680 -673778 -481406 -177299 -487148 -491479 -132152 -860488 -473510 -877331 -305126 -940558 -51263 -926284 -696956 -201121 -44846 -115248 -414207 -465126 -678373 -158397 -910070 -280774 -40888 -279319 -964952 -628536 -986922 -265082 -526058 -923910 -303375 -645517 -944336 -263329 -458924 -737632 -486770 -822683 -450368 -693760 -143247 -149147 -696178 -552699 -658262 -799990 -64279 -397854 -982926 -591105 -154861 -498534 -101209 -116576 -260453 -392445 -885385 -559932 -743168 -317424 -510466 -675794 -631471 -808548 -257727 -205633 -532575 -932930 -962726 -108001 -866478 -484993 -736721 -372758 -530021 -519641 -550598 -371405 -554671 -423411 -430620 -6634…
Output: -403685627

Example 3:

Input: 2306 1103 -815598 -675815 -617620 -521569 -930585 -731815 -475368 -896412 -766070 -993217 -888754 -692841 -858398 -347538 -520460 -119697 -583989 -926673 -936646 -119702 -627519 -651324 -10535 -453516 -920388 -196584 -918800 -416179 -58682 -772783 -645691 -854327 -183499 -568794 -313935 -883924 -478699 -516927 -449267 -702776 -29009 -642819 -978332 -875328 -253307 -939671 -695066 -622342 -375140 -90352 -118033 -997284 -357807 -132968 -644876 -738127 -777759 -37390 -191150 -258167 -466413 -54966 -566244 -863853 -379917 -320742 -931431 -16930 -889427 -283928 -631692 -662864 -509450 -169320 -580034 -454824 -35514 -131287 -397848 -186456 -404320 -721524 -148090 -779900 -610953 -764608 -399088 -9211 -300348 -744381 -74615 -96093 -7979 -494799 -893399 -599746 -571166 -154275 -147376 -792007 -259…
Output: -546677445

Constraints:

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

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