CT44756

The stretches at Whitestone

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Milo found an old ledger of stretches in the dairy attic at the alabaster quarry of Whitestone. 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 <= 3418; 0 <= a[i] <= 1000000.

Example 1:

Input: 1047 827 76512 927543 87801 561137 499668 500977 564949 958425 389900 753253 91007 909239 799085 954035 128612 862676 273385 193825 940507 75443 816436 299201 98750 801456 754166 899322 978302 508154 380713 3381 824774 377000 575274 533612 140373 665010 123491 30464 738827 161369 639821 473661 667107 537281 508578 356154 988551 198579 795029 552681 536847 584850 482586 872874 223041 824115 702156 932432 348491 206954 646894 169292 594294 499323 551101 812963 166008 917501 821646 707546 909628 997225 709392 80583 838245 857233 924792 587766 815710 53595 389158 846120 314467 890786 616642 698436 472702 819473 187837 748412 807330 928135 237856 595666 665813 283276 337457 416723 654574 297859 59315 504974 796509 331156 711054 147015 832602 414165 401381 489023 267681 898418 48114 19569 939003…
Output: 423629897

Example 2:

Input: 3174 1084 328480 487653 563981 314778 30113 954118 932641 449553 496175 57648 483040 603676 191833 436527 769040 56557 330618 566602 158591 960159 582986 591114 79567 219923 225367 830677 988356 316591 28135 145417 604916 106749 147872 784576 294995 315968 612216 119325 156337 49576 209448 181415 812762 621977 309731 166382 697078 7653 909847 712896 67304 740192 390614 931882 690390 651953 519861 884768 482175 749566 644570 812051 511529 117783 227521 778981 3464 987693 206337 447428 47163 999458 13415 239019 669102 953123 610713 572084 554995 423958 36507 369076 366249 659028 387924 867841 266092 438003 359186 765264 775677 492696 50601 757121 466592 938545 661833 760228 107456 562629 719183 99957 714060 182148 802521 978095 94742 851670 615882 440688 462592 38073 978195 398586 80205 2574…
Output: 557611860

Example 3:

Input: 1605 880 165824 922692 18693 373340 589945 926535 147990 367076 87160 771237 930782 414181 861578 769032 603141 581286 420914 589567 568515 384196 247721 260323 157464 480210 497248 307488 77156 102664 320378 982206 691429 586201 61454 399531 806155 338989 905427 318074 554229 606231 864510 425422 46709 936716 619274 378336 549388 317636 981640 828472 373894 933454 740208 644102 181201 961633 901598 467779 608432 155958 606695 80527 936253 406202 637123 963627 351055 734866 687306 632548 832586 397258 550692 749257 932214 813701 190684 780057 690283 936859 193745 587073 135032 369199 144932 964434 492201 711583 121567 632010 680010 747382 498772 160623 739968 656687 133982 168358 803444 629019 355418 92280 549910 458795 945078 423990 500583 360988 328545 269567 233451 805504 650696 458460 …
Output: 454028913

Constraints:

1 <= k <= n <= 3418; 0 <= a[i] <= 1000000.

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