CT49227

Zoya and the Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Caravans arrive at the port of Emberfall with crates of windows, and Zoya the assayer 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 <= 3079; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 368 60 -651788 160756 997879 186312 510917 512062 697713 -921196 681917 -97903 50980 -519363 450601 -130711 -221820 89707 473548 -126173 290202 -207493 846550 -955522 746607 -873944 291462 203164 333892 481916 507590 -123830 -116690 -540419 636191 -330042 -649306 97211 39260 22549 -592020 -451454 28077 -121151 58586 -634252 -624938 954896 -404231 621643 -962840 163716 -878294 128977 8117 -329573 -988730 208332 -749993 987542 216317 -565431 990200 -991328 217509 -74658 732222 -993069 -676289 -998482 -522352 639811 339681 319519 -297405 -557725 509132 -741939 -944719 -149560 -776613 -760253 -363077 -159007 194134 941355 157683 112940 39941 -184408 270444 498058 670524 -788572 -400045 956545 16553 462879 -285200 330245 -14940 -836279 -3454 297335 -270932 481891 815853 253145 -252745 -944781 -…
Output: 7190973

Example 2:

Input: 1882 450 -18366 -86292 -344698 -468432 -249591 666828 917925 -23903 39823 203027 -670985 -52552 916637 -944260 -295194 224439 -809014 -719491 -20564 379349 -882019 -335423 704878 515653 -645553 -575885 -32338 -776092 250223 538536 -893423 247066 451066 -178398 -137626 407249 -787736 -238304 -869585 -384446 804154 -546583 65334 896661 318575 -908671 310862 838747 147576 667159 158140 808135 132269 70655 -879222 696732 -670466 895593 379419 379007 -754814 437956 247995 912707 -666669 312742 -915526 -135059 -258878 837499 -587061 -261766 65223 246432 922939 282995 447194 -836230 -441384 -744946 262020 -662418 435787 595680 906136 858400 -735589 452443 -736067 559860 625002 594838 33689 -649860 -986447 720851 -838985 -526700 -552365 -346031 334802 285576 830406 842764 651484 -898365 311081 -68…
Output: 24291919

Example 3:

Input: 2830 2748 563495 -646680 336956 447221 798867 -931087 -626220 -668703 -737022 -938742 595256 490700 947687 -258534 419390 39909 -612598 697064 535876 966903 588942 525494 -88251 -993071 25026 -934417 629850 -359748 -444380 -703211 -100949 126899 326054 -664686 -297134 -463033 777052 -199174 292358 920721 -669239 -198096 -531582 373083 -798153 -168656 -951570 381184 949292 -321871 34937 686211 -283633 804291 -716157 -619909 337754 -733564 941470 -921045 342353 470171 106029 106323 114673 60087 -209315 -955753 -204693 640561 -130796 883337 420877 -227237 242035 -367415 448870 171647 163493 -288206 -463015 -631667 -657345 79188 -340057 -50617 612708 398777 13147 705744 -99134 306183 -903899 449326 113581 -695176 -776983 171182 579750 -736344 732726 120527 -641893 815820 -10950 -116248 -761480…
Output: -30666464

Constraints:

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

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