CT37320

Tomas's Ledger of scrolls

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

Legend says the vault under the lily shoals of Padmore opens only for a perfect tally of scrolls. Tomas 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 <= 2508; 0 <= a[i] <= 1000000.

Example 1:

Input: 143 110 170372 812226 300976 67482 805764 277029 768482 477070 54949 930285 755962 903683 430720 748247 221973 714814 785702 725921 76313 735311 737002 104090 551453 42818 851875 739002 76740 534810 226784 797087 15141 833993 494340 725568 542293 571694 49751 693142 93139 321062 388242 487735 182172 368001 741356 490807 824393 35837 78526 272868 311280 970642 452017 229650 473492 333485 482553 606517 912574 489248 927264 350443 734576 227730 932759 145891 207012 134408 210982 809872 361413 573892 451584 718600 992408 913351 489095 646405 58482 80330 142546 593193 754417 983129 892971 272531 471840 902944 783663 516509 606650 69714 449860 875934 582748 708188 876538 870089 992136 64390 792143 567462 662885 332356 359845 580289 811567 704178 507720 515766 396017 977426 310072 236325 563537 5…
Output: 59319685

Example 2:

Input: 306 246 224252 401687 472129 352663 186469 114457 518978 247690 323769 588047 631195 489264 798609 341300 992856 607865 241408 121612 898167 42874 933241 389011 904521 481060 692205 620092 844712 789051 88616 173023 58648 86505 612846 910972 652369 558924 919227 261576 391579 878831 905031 311101 872184 752568 704384 958590 802430 107369 161307 359701 259402 336320 398096 798814 995380 862803 324996 47160 1765 167149 689321 846594 899950 565287 188101 679696 100847 761276 993395 872116 824151 143300 233758 893117 908901 252877 25206 841378 333137 893481 451330 915647 112601 268947 1188 913199 919229 379385 893489 455475 446764 483221 10360 434017 913225 940058 414289 955121 679183 891942 625929 118087 823161 827610 855822 267759 519741 776882 879340 170096 270770 453980 17254 891939 614890…
Output: 121255814

Example 3:

Input: 1118 15 981872 205548 296918 156426 326268 956535 384513 201089 553373 134090 797373 291711 940892 955671 98078 686295 808555 629770 6120 112518 977289 82388 481336 242530 273683 823793 305818 79129 678029 430222 739811 822998 557527 883011 346026 288253 936766 97497 60934 541662 400465 606932 6273 671344 990708 125133 726650 205935 62673 300981 950375 437491 268402 112430 65932 64475 604597 853399 365985 441566 866967 390148 840951 346565 165178 502980 629984 181515 746148 189022 991564 879856 548440 427945 225924 206468 394135 71619 961944 990896 245809 781792 640995 467261 488494 780550 123641 671222 52462 890708 331450 926237 489030 714431 32001 60869 287574 245672 167164 105758 955389 93194 157226 723224 948329 23338 197936 992963 870292 550969 445522 782 148519 559303 868707 655843 2…
Output: 11329469

Constraints:

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

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