CT42292

Moonlit stretches Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Before the gates of the tannery row of Leatherwick close for winter, Elio must finish the stretches ledger - one figure at a time. 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 <= 1383; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 82 38 -758953 198670 -770254 14730 291681 149098 -108701 883836 569624 824133 401416 852892 -643164 -726952 484534 231657 866600 -333040 140336 58431 182507 968933 -244434 -236643 975066 -285022 -449923 453230 225514 48032 244505 -596985 844882 -470352 535924 569865 -697805 -982101 222072 -241073 220171 123945 -680805 -771455 517066 -961320 368387 237934 154339 449936 680711 853801 -378260 14230 319327 -39689 -844164 158780 917590 986818 332585 867198 569945 -373099 956693 -607996 886765 677393 -461785 -405881 -506726 153254 -464861 -934343 352599 -195867 -618688 -930016 -227069 947727 668302 250579
Output: 5352689

Example 2:

Input: 442 19 -427749 322735 960307 -725578 -773798 394386 -438016 -572313 651546 -582839 663727 -743163 -888418 663210 817443 316369 -745315 -737439 -794145 -805037 595479 325124 -140204 155410 826922 965801 -921504 -472577 201332 97305 699672 221380 868594 -1993 606705 105214 745455 -987170 -495709 134464 755880 -124149 582226 -771999 -262024 785322 304450 -342252 -972911 -217299 -73048 -35585 -747916 463610 -66553 -634536 -947840 918958 -578413 -225136 876217 885437 263689 854345 191837 -930124 -929881 643395 -68838 236166 -345807 916129 -380641 143540 -432071 -863180 502445 -504332 158040 545958 -652765 -524733 884489 -668482 738555 -467342 -299991 656044 39633 -908171 -517464 -49484 66708 -515884 929021 440849 180786 481345 499853 551399 63371 -423212 818595 -943015 -955264 -826682 185356 -5…
Output: 6149197

Example 3:

Input: 916 403 89894 -117055 220370 -580924 455635 -164134 237298 587086 -953864 -695505 47884 850075 64641 -827256 -116762 875700 236869 -627554 -184149 878791 354643 110334 -565600 456940 171936 -987186 801678 323484 -287257 -448138 -708155 425857 243157 -160195 -511412 502092 -237132 407312 -274692 -10315 718245 612540 55980 -646985 73209 -252445 874985 -557847 -611776 357788 -521109 43686 -879377 457848 562317 908595 527379 302277 511886 442 -701424 196200 767455 135311 -748691 754424 -652467 700079 368720 -385637 852971 808530 415933 -635426 467267 -161845 720532 -40271 -393724 -348334 640559 -771973 853647 -372430 285030 -726702 197880 591234 726720 945630 -460390 838955 -464578 697676 116672 -684214 -277381 -807787 307624 704340 519288 -689770 761254 12485 47388 182335 310098 -760175 93453…
Output: 4381236

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
Moonlit stretches Fixed Window Peak - MEDIUM Coding Problem | CodeTikki