CT45285

Odin's Rustic ribbons

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Odin inherited the workshop at the crystal caves of Luminar along with its curious bookkeeping system for ribbons. 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 <= 2455; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 488 148 266082 -753139 -684535 -454415 35515 302487 -338193 206896 -234474 380566 -855151 126883 224616 -119243 754974 338347 -547447 489104 -911682 -116245 -877268 -856875 -968671 326806 883089 -503670 652165 737407 666487 527290 -777703 851142 -415273 -885356 -273608 -63171 319534 -783634 -642939 -260115 382365 851212 370271 -884738 -348865 -141854 -56363 201219 -209096 -492569 -466621 -236020 -537224 -664743 843274 106746 281264 -320598 -548798 -761574 -91178 -322032 -565209 389107 -224060 413839 -288050 -328629 -926046 -498308 87632 -288465 772983 -426933 643370 291588 40903 -984916 298083 813476 586674 559470 801753 -362529 -950610 -409938 -852074 400894 -257182 632281 -222172 -219973 439526 712578 -259283 762136 -385893 -109348 623457 -118646 998508 -142314 533597 -351754 -408847 117…
Output: 5632754

Example 2:

Input: 1274 80 453254 -350045 603492 365072 -390993 -341734 -184957 370287 -90220 -110878 -695651 212445 -69634 -486345 745704 916580 718600 -139378 236307 -727199 -238010 869532 -822839 -873306 -88931 -173952 677519 -226265 771829 -534953 362368 -655959 716838 371530 -994230 924310 188104 751751 374492 284838 -799694 -184743 827665 -716305 928651 -946990 -860877 -723210 350631 -375200 684609 -354523 -464 -575769 -770896 370946 -90463 -286193 471356 549298 -759903 -81676 856464 -562677 -425677 -774734 799218 -992484 989519 -342093 429879 -851722 -106371 74641 665641 595816 -195001 239154 750238 214453 558981 245143 -296122 101117 28109 480584 145916 88897 -443323 -586161 245939 -967927 715669 235220 -82206 772341 730387 -140169 -415040 971502 -93145 128267 695459 -211133 147079 300492 891741 1804…
Output: 13817260

Example 3:

Input: 72 17 -619551 -572490 45796 108013 -854686 -111602 -285284 962028 -532122 892433 -938151 956440 301781 -384397 -213440 484959 207970 -275687 618080 -505274 -798135 -604611 -813570 513356 159706 -972905 -15322 625310 303167 -42694 487421 515003 -427305 83929 -361657 -317305 541278 776991 -76189 -808934 950012 92328 683768 167214 376157 -143609 -235113 -768211 993787 644112 394566 705690 937656 -484325 -178988 752669 -692008 -272732 963308 -948817 -986843 698277 -50768 957821 290310 -215533 379039 759734 -47512 -95302 -819811 981194
Output: 5231503

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Odin's Rustic ribbons - MEDIUM Coding Problem | CodeTikki