CT43141

Diya's Ledger of scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

In the zephyr cliffs of Galeholm, Diya the quartermaster keeps careful count of the scrolls. Audit the season's records, every figure matters. 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 <= 3143; 1 <= a[i] <= 1000000.

Example 1:

Input: 1097 927 170076 542065 304463 223900 246706 693365 606706 101487 189562 675985 627399 120005 408265 788990 423450 661805 296912 749182 617944 81721 391294 371354 555651 902932 212063 244152 133521 550962 657057 785498 667066 447065 46694 183957 794244 504950 956567 171749 189024 983443 895677 742669 771709 958878 117581 513851 904668 281801 722486 974550 494526 492499 500485 442096 674271 689495 488617 278867 314024 42639 81846 728858 608993 816701 688266 176387 839068 719428 362525 279214 221428 235560 96253 491634 90112 950233 583951 820302 922491 597418 394986 963820 228403 825396 66928 531794 630157 29188 712635 694969 879624 288917 637570 733977 593703 291724 934001 968854 799716 1058 26528 190375 402275 172015 672536 572692 975490 945592 49106 484017 402405 109636 85123 514895 654212…
Output: 458567130

Example 2:

Input: 1546 1182 917568 361916 272449 680482 114106 205078 948448 456511 570083 712767 857676 754071 306692 163139 421868 205919 995392 954050 905571 813945 851049 932966 922428 790476 510241 225230 509886 641560 405960 825851 332112 672267 926797 583287 713726 831992 581173 639477 68549 31460 48546 187134 166319 613882 44951 204137 489022 528045 435315 609251 235717 324918 639288 781760 913958 842919 8491 436859 576138 576260 590839 353629 54820 561831 731379 294375 290420 850365 190166 900833 949971 906781 786331 74745 132388 868583 121973 569230 709817 638336 699690 296531 669054 366891 342434 294444 860644 851337 460249 365896 154159 341037 551033 919336 108586 79654 473035 524935 299757 334435 253901 388161 850817 443009 686935 860457 376208 577157 675317 230995 471352 836740 573959 103448 6…
Output: 601818145

Example 3:

Input: 710 500 829926 369155 659083 38519 197272 416277 168368 167496 111002 255987 347975 909697 942122 845734 908245 651314 921565 601632 850592 751625 83030 98470 798072 357700 341790 657388 462902 171942 79741 306870 861000 448587 176559 815896 705240 372653 661828 610652 347323 388442 226678 966428 180028 86558 29670 776796 54026 577396 317019 553149 172895 172145 953876 65725 713427 746783 382972 690664 318670 868186 259443 960043 558791 164395 170438 284338 744248 870997 13724 430369 395185 433441 473395 283480 434269 211104 971564 992350 333441 373499 58086 582578 53942 442201 621814 101695 710691 125040 563336 409584 830871 584456 91861 988308 280121 738880 453353 630795 593111 823831 886817 268230 422587 196444 443939 458492 311542 475428 764003 535054 127408 813798 802753 968874 637813…
Output: 248382871

Constraints:

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

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