CT52907

The Scrollkeep Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the archive halls of Scrollkeep with crates of segments, and Nina the tallyman must account for every last one. 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 <= 2452; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 1183 1031 285948 -117169 -33962 207487 -682912 -116778 59342 337866 -968337 163157 -901249 344380 -230737 -89910 729324 -711426 486302 -622150 778610 -302525 -345556 -293125 595570 759273 -63561 -568190 -192446 -922346 -756703 -986020 152548 -312509 522398 637212 -156109 -28751 -262483 616449 372180 -685775 -166787 418410 123681 -485967 726053 -163430 -734093 -405850 288422 341598 -790341 -238029 109043 573042 152869 -74067 -507170 -721121 -305541 330566 -849598 416685 -873018 -755887 854487 479005 -613047 -486231 984554 -488050 -917280 369273 -700950 -903188 310861 799843 411575 -79947 -277121 324227 -830930 302360 830404 -282856 -463052 543357 372705 -542432 393325 373281 54438 49535 -335306 172356 -171094 515295 955080 429 -292197 2824 334276 140592 -191155 -196547 199734 -375034 527348…
Output: 7557224

Example 2:

Input: 2063 1193 -902662 73314 -223625 -53773 -472295 -63039 -234151 -504287 160893 983953 -520562 -926748 -340936 759050 -80033 377226 -567077 -678762 192941 19465 -667065 -463914 -341152 -856085 -226721 -131190 982309 -352215 -838442 -75076 -916252 95149 674775 89330 383842 680267 385818 -700366 -170254 392750 594088 209122 -353201 374161 24382 705124 145146 -9576 110833 729120 251858 8235 -118476 429751 -669066 -301070 -703349 253372 956159 977317 -317375 143007 465172 591656 -637809 579926 216999 479128 700311 515861 900291 -593580 810461 -20041 -304205 -9452 196857 -364642 -439336 198452 73098 -138312 -933873 -521142 -281633 -898910 511086 875506 -155769 -266771 -66390 581156 -694308 -722838 -700613 562717 946619 509906 -759524 -261444 -798878 -210051 841852 -697468 353405 -114533 -658820 36…
Output: 22302853

Example 3:

Input: 415 358 30254 106354 -7836 135182 953449 -635905 -230176 -60062 -844326 583432 -156568 782015 957489 -913451 -112839 807579 -8266 -654228 446356 281464 766150 815009 -101955 850411 -794133 -989611 799032 860798 711971 950007 -544204 179151 872799 -558305 -824140 -541742 379012 676971 -635845 -1773 -376402 12182 324090 625820 672735 543584 541761 503388 -189033 244104 -494199 -407194 625672 -447139 -917336 124002 305874 -365088 410462 -827110 -183572 737119 842141 794148 300225 626946 382358 -760289 -929958 -183734 408270 749887 -723537 470628 944243 -316139 353385 980075 -920837 -371168 -331849 -848971 471304 572699 -983477 -104648 -38600 628727 -778643 523200 -365433 -496382 958423 502581 -778499 972269 -781446 -991847 895736 -439233 356475 458817 564401 979791 -961877 454086 136780 -9281…
Output: 7096784

Constraints:

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

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