CT40242

The segments at Alabast

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the ivory gates of Alabast opens only for a perfect tally of segments. Zane means to find out. 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 <= 2649; -1000000 <= a[i] <= 1000000.

Example 1:

Input: 237 90 -918108 -728567 162000 649673 384360 112320 -144795 78799 483102 536738 -313296 -303044 -240722 876942 -665993 602438 179797 478037 -487910 -937139 387680 726196 -557676 442343 -168197 -260316 72120 682253 469199 151877 -190814 -122327 729507 390913 591291 325370 461098 326552 647184 -397548 -716134 -772142 268468 334808 791091 3257 -839220 -198575 478583 -684775 104852 -499176 -55350 735390 -958492 -856022 -199519 -574302 744298 -937850 -966336 -581247 -816740 107719 147049 489119 206456 -956949 -139128 581732 292582 -708024 594378 633426 478357 427752 641071 239697 -587150 727554 -18166 803831 906426 519604 686753 341384 903610 871860 -140097 -299217 182556 614448 375103 -35948 421676 522354 330065 170701 -218882 -110199 -316996 235048 333747 395498 698699 595461 -60448 -695730 -2…
Output: 9696294

Example 2:

Input: 1890 545 547205 -905614 898335 756548 74541 557810 -477547 487941 20822 -38346 -216570 396672 439838 125199 298570 245486 -452817 -305147 509240 639262 257143 -528761 583773 280732 -981588 -985635 -382710 -963011 821848 -679467 -755314 -712904 -36004 -946792 307475 503440 -355690 -489944 -211691 953565 173071 -952183 -482129 -685892 -984573 -99502 -300153 -537193 -55925 -774105 -98822 977738 -10893 -67136 -516173 -158042 236734 -451968 -739149 56941 -522243 -228509 888993 -328105 827930 743944 50183 967763 518567 544758 145900 -257244 -373125 -182023 772734 107291 -525371 334637 -600613 -605769 736446 -434962 977968 -123998 -289919 401069 643771 286162 2441 672864 169024 631434 -983493 -410964 557410 -188494 299385 920370 19465 638263 -363631 765097 554360 -218630 -687916 257729 607862 -33…
Output: 20483412

Example 3:

Input: 803 215 -62442 -768834 -687636 -191262 674691 679828 749076 -873595 -876499 -328600 886676 600421 -597602 349077 -72324 -205031 880989 -339557 268257 -177167 -143470 729361 -158666 -431251 -918240 238640 -236092 571714 159433 788358 603876 -566330 259463 443190 -185879 342364 -202137 -25467 833267 778690 -59785 -526653 291533 465272 148476 975709 -700647 -293830 260497 866893 265019 -239314 -466503 -467577 -86751 -182244 192998 933577 892807 -923532 -322658 818015 236666 -212501 569097 252699 978396 778024 109359 440892 -251321 3983 -815359 -79688 337263 -100361 -140970 132642 -995363 701382 419516 -749499 -985156 -537137 -109439 -301923 253526 -786517 687746 -736076 -152674 912111 -84382 720508 -116314 -267775 160968 -367559 88722 750947 573260 -3914 264867 -738194 -439110 716167 -35761 6…
Output: 13123191

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The segments at Alabast - MEDIUM Coding Problem | CodeTikki