CT42123

Gardener Counts the segments

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Gardener inherited the signal tower at the kelp forests of Tangledeep along with its curious bookkeeping system for segments. Time to make sense of it. 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 <= 1159; -1000000 <= a[i] <= 1000.

Example 1:

Input: 868 568 -761002 -241280 -935987 -555294 -219743 -853157 -102124 -60033 -16729 -459637 -944347 -96688 -951277 -206168 -903333 -242684 -380079 -94825 -924829 -617531 -229153 -824829 -404682 -579737 -597121 -611901 -623713 -206091 -353875 -935922 -225745 -13230 -341673 -509194 -993546 -377630 -332426 -140823 -938830 -42695 -283679 -486026 -587745 -839508 -499965 -563882 -66980 -576967 -106239 -992835 -172107 -331885 -238144 -105348 -106258 -983378 -337083 -755554 -57503 -403539 -849505 -269758 -459005 -909088 -276979 -43841 -795983 -768105 -919699 -858310 -734450 -350457 -574451 -438688 -276468 -52837 -915779 -94580 -891123 -754138 -309347 -570846 -707058 -477076 -309964 -43640 -845407 -281398 -778876 -936351 -228786 -667845 -483572 -939126 -741095 -687692 -504463 -936388 -674662 -17490 -7918…
Output: -286168792

Example 2:

Input: 1039 495 -270083 -558653 -725884 -354569 -685234 -182355 -207349 -764895 -122454 -375551 -113329 -97207 -589559 -272143 -895947 -702925 -395664 -493976 -225475 -503686 -424478 -367540 -410596 -509851 -887815 -372801 -438472 -877465 -20728 -677174 -279159 -190905 -398941 -38497 -919815 -384119 -343337 -86152 -788194 -995076 -673748 -220663 -184334 -221020 -133227 -515540 -385027 -683214 -296421 -984239 -643161 -823652 -862790 -435573 -650839 -838934 -545184 -949682 -923664 -431265 -687841 -965159 -701398 -956905 -134552 -213832 -252012 -599889 -657491 -337853 -387111 -955395 -777525 -904707 -105728 746 -303537 -533634 -695493 -175604 -41491 -767089 -688767 -918394 -794040 -478985 -567481 -626098 -75728 -418026 -848331 -922483 -750113 -901205 -626901 -666250 -820290 -701537 -853137 -743329 -…
Output: -236807347

Example 3:

Input: 16 10 -274199 -351781 -498057 -979400 -746082 -739085 -68499 -717451 -297687 -839902 -35557 -403953 -921492 -98204 -118876 -993667
Output: -4240706

Constraints:

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

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