CT52913

The Ember Fixed Window Peak

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Boris found an old ledger of ribbons in the observatory attic at the glass towers of Prismhaven. The margin notes pose a precise question. 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 <= 2836; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 2477 1150 826804 -274706 -724008 -444553 -215306 168156 345126 232187 -571453 830465 -236748 -178067 281483 538114 -75627 -561155 -192581 -954014 598942 -938699 -19717 266982 938547 436254 -456701 -330084 -998448 50444 642296 -282320 -335090 775134 -663624 596066 8113 838507 -850445 -889044 -310169 -965019 953802 -17376 555100 -596622 21017 171407 -857979 543654 -735989 952202 -192453 471085 135875 628221 -976509 -992568 -388493 877875 304137 827858 321565 171542 77339 486714 97346 -814633 593425 -701462 169439 -412744 -651109 -510956 336450 414127 -131517 705105 -107431 310342 384417 894144 133116 600762 359041 -569490 133281 555583 952839 -646514 908858 -236548 192269 999766 -870480 771071 -990860 382113 -635132 -492860 -318491 -463872 269488 -686493 -549918 326241 679664 -672650 -625314…
Output: -14022591

Example 2:

Input: 1505 305 -131218 -910425 315609 -672910 776502 205604 -570685 896014 -504513 372072 -392184 -365822 845158 4530 -71261 377431 -15198 125763 82320 -336966 504837 -43832 -54021 34040 181045 -514479 -767492 -595601 -944700 -443156 -240629 -376349 721769 -545952 -143595 800522 -573182 161814 -293557 275012 -563758 -146208 -798433 -251361 -449154 359238 34357 335797 -665740 -76879 -346766 109965 -88845 22407 154698 -493330 -399371 714729 737495 824820 154075 271419 432548 810852 34083 -133692 -567047 612936 76409 -693691 384928 -973231 -465814 -970727 -844883 -291817 15437 320951 653574 -243157 -415812 457876 -580753 -769647 -807689 -356496 -355007 320161 -425197 150193 -369732 625274 172941 557699 255846 -774654 -872859 874179 -284502 -171193 -603583 -774572 -265975 873351 663996 -859815 66916…
Output: 26449344

Example 3:

Input: 117 14 958002 -166477 -897542 -143427 -310768 228124 -734044 850984 231644 27297 -679022 582849 -408832 -60932 953519 387272 395534 -606150 347390 105082 -794461 -608919 -397865 232986 -474532 -380091 -627947 775858 29393 935945 -642338 -726783 957507 -643895 777060 -800725 883719 -208166 297842 619347 156938 14019 980969 652683 -442588 503151 910097 441549 597042 871354 401822 -623478 12421 816129 -81719 -251394 -267745 -584132 225926 984907 -395315 -23910 -797888 -988218 807196 115763 989162 -901811 -779086 -731822 -637859 358767 177470 378025 -715586 273310 -44781 -108833 -88485 -208129 187927 703821 762333 -270687 379340 196140 928366 936422 79345 -957283 -416787 722823 -957114 -164799 717821 -17287 -116709 -137103 -721148 -839746 711511 -541838 576410 953738 -277698 -709456 715323 510…
Output: 6277956

Constraints:

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

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