CT44566

The Wild segments of Forester

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

It is audit day at the cliffside roost of Stormrest. Forester spreads the segments records across the table and picks up a sharp pencil. 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 <= 3828; 1 <= a[i] <= 1000000.

Example 1:

Input: 1605 1104 365416 613052 501867 304017 33577 181840 251099 961384 336139 407013 55827 988887 303982 34611 732990 266448 910504 928548 440423 836343 789025 65111 415583 987649 205728 439846 133577 913680 374106 263915 602781 359583 868840 236453 291929 621963 565687 452847 852040 623272 668625 540609 905097 489067 524526 286776 395054 824080 781726 990137 150484 86268 896799 863695 895382 198085 389181 83893 374307 815563 409101 997826 515897 781819 465272 519024 942296 655698 209187 804655 60353 75203 956499 150420 866491 116542 918456 849931 690602 379625 815205 771888 273750 692876 594095 278629 215060 878047 319464 895333 907585 536880 391532 630672 668080 528756 520897 284590 116089 647808 777162 430065 48136 623100 936370 65944 160720 81770 900447 192097 475580 17519 546389 587029 1786…
Output: 575722121

Example 2:

Input: 2054 968 478974 304922 267608 544658 93585 46896 852447 460010 444149 110259 198669 387521 41318 200183 406887 285719 467006 980250 239996 612149 581918 701146 891527 348556 155060 441140 864335 748142 499045 506900 520587 141753 202142 393166 915748 348379 134610 145306 406678 627438 163869 840285 39476 428516 633326 903587 647372 77920 548653 969836 84946 575663 313793 430524 192615 175735 478563 42664 579583 388234 508771 483018 915426 126177 329120 845260 933941 986702 740122 236667 875557 67514 154599 385516 947803 61567 717567 959716 415823 74320 777641 227530 506444 692441 95721 549558 643028 363599 547769 412070 519055 278140 538524 99742 358543 941377 613313 584281 657480 396815 601927 492676 278095 47987 960565 887533 434941 185260 64022 591341 141440 960652 147743 587192 69308 9…
Output: 494203747

Example 3:

Input: 1380 1045 23000 348257 427962 907701 550548 367119 242434 928139 866631 154853 941543 207247 308903 887663 213659 587968 250644 635096 982654 122134 521816 171973 619863 340545 380963 310788 162170 56600 867034 233771 195601 689085 497647 141072 327909 102142 511313 719847 781004 981693 639360 844298 115957 388689 185183 237993 405033 883169 949787 951395 558661 877589 130663 791749 672783 12531 266005 683055 445765 520060 448259 761445 197259 479544 669954 937591 603161 331652 849140 324769 455723 952501 91163 576795 382418 72288 622969 652956 71200 353181 492300 867633 230892 614676 257827 407456 464050 234318 737058 486377 354677 737846 321743 42869 533966 84473 651952 654290 951906 24428 87410 639072 576288 710904 574194 714024 442779 95764 563350 797983 339263 81690 215744 700925 7868…
Output: 529446257

Constraints:

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

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