CT30746

The scrolls Fixed Window Peak Puzzle

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

The archivist Lysander has been asked to price the new merchandise line. On the desk lies a long table of scrolls readings. 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 <= 3241; 1 <= a[i] <= 1000000.

Example 1:

Input: 389 232 928696 375175 812456 264443 930050 309089 773311 191214 519072 88979 72418 281962 969159 278582 891082 10102 345799 928955 569590 623760 740297 935941 288843 835547 326334 173811 223196 633202 294415 325958 945749 516495 689783 98934 924242 885608 935024 712055 725703 10634 947254 980357 693954 211503 85963 493746 840666 690453 448186 137138 586958 543484 786455 873538 836698 760092 714055 987482 547477 45221 686308 761391 579166 31583 846649 804149 569791 604432 980738 962560 208983 616058 911533 811502 666931 489884 569706 623709 400831 903932 485214 836880 610651 54805 987008 645090 539165 513757 679400 988993 7721 2335 891280 875223 852499 401836 449100 276086 691792 697999 408410 160315 101828 540571 498651 607999 800247 574296 647528 64629 139287 193496 333207 353329 648764 9…
Output: 125366023

Example 2:

Input: 2451 1907 459648 631756 950191 23869 20316 424267 265996 557437 131009 847790 637249 123519 126812 294766 631478 827894 713023 634491 957805 691205 49802 916453 20939 581543 165889 326847 393931 248169 632401 8302 893097 371731 785066 135775 424612 857618 265618 475341 67010 935792 343836 541596 60740 837829 966704 540720 160601 248284 540182 405789 130733 854763 886433 73880 72651 13341 613433 248874 786956 782540 938307 475006 529653 943943 925210 104532 18955 166889 52191 317590 229053 73644 401596 269048 775341 752549 600402 278288 751106 304414 700761 196864 346884 280557 564372 934296 897156 741919 85499 396044 603923 383142 173307 740837 602390 158237 28544 485912 249212 751597 62825 264609 307025 834818 361981 993412 921767 960961 563759 454813 130262 186515 320774 852131 75913 529…
Output: 966547551

Example 3:

Input: 1466 1148 593445 974013 708807 902787 386605 844670 850267 439304 153847 808573 419281 622766 383148 371530 739344 625545 783396 359912 919372 239690 900099 550068 760966 891302 408361 797604 649828 854123 470290 573968 733424 951633 622090 856918 236940 37914 355437 67114 944711 715132 444249 707146 383001 887616 180957 386690 89792 922082 534634 763286 53145 655824 585546 253380 680104 278809 778721 36155 749540 660939 977870 99577 477355 768988 711275 495982 565460 187317 682594 850635 810699 987182 904845 628539 906 150375 479101 151096 213679 717096 248852 790715 567816 940466 861842 17487 447572 7363 473729 585740 641457 44042 39310 424672 694069 815446 632274 556944 135612 222411 751820 8159 964740 397463 674987 894693 106248 557642 996925 721592 589789 9558 742373 870329 347415 823…
Output: 582654106

Constraints:

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

Loading...
Test Cases:No test cases
No test cases available.
The scrolls Fixed Window Peak Puzzle - MEDIUM Coding Problem | CodeTikki