CT29850

Pearl stretches Fixed Window Peak

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Before the gates of the glass towers of Prismhaven close for winter, Zephyr must finish the stretches ledger - one figure at a time. 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 <= 1777; -1000000 <= a[i] <= 1000.

Example 1:

Input: 1398 1160 -603283 -427064 -463696 -351597 -241920 -782430 -167497 -183951 -917343 -693139 -991075 -540040 -652013 -391436 -903686 -733442 -946085 -428011 -323814 -991861 -346429 -701869 -943248 -541638 -404348 -748521 -860069 -715929 -48309 -432457 -654084 -300027 -485656 -278756 -677289 -320438 -964360 -359151 -846085 -908847 -741355 -743434 -28121 -911896 -611179 -463620 -578558 -65931 -355779 -192282 -428395 -450020 -233712 -88879 -662574 -838754 -677672 -735412 -506618 -592724 -327444 -6803 -782139 -169188 -585140 -119754 -434110 -561908 -781146 -567810 -868857 -286044 -576800 -374729 -459067 -82799 -309927 -167347 -121678 -91977 -208279 -689828 -41635 -503698 -35084 -345397 -33402 -291676 -674491 -689177 -361427 -318007 -926077 -448342 -658876 -951922 -875815 -536824 -38055 -916102 -4…
Output: -581950307

Example 2:

Input: 1476 1022 -269647 -471302 -94553 -633544 -870080 -724633 -624103 -737782 -884935 -604849 -596389 -567077 -138397 -674731 -597607 -139443 -627614 -538126 -445651 -465000 -462040 -537095 351 -985660 -746104 -323074 -877749 -262546 -971603 -814496 -268492 -885187 -404683 -905057 -422697 -562729 -191565 -134064 -192582 -721382 -407988 -385200 -635349 -407601 -626373 -742464 -144753 -965493 -477311 -744522 -320647 -565892 -581124 -199526 -854903 -898275 -824819 -757974 -353195 -150270 -868263 -507438 -442027 -356102 -647458 -611316 -564806 -806654 -684443 -548054 -418439 -184581 -612954 -332608 -183281 -319528 -659107 -69924 -865264 -512491 -288383 -651010 -406341 -445136 -990867 -133929 -69073 -509786 -513669 -212917 -336077 -807598 -422386 -69089 -84521 -90388 -917567 -878507 -277820 -684607 …
Output: -509805212

Example 3:

Input: 1364 692 -144620 -883965 -790746 -732316 -360825 -518268 -477463 -761643 -104161 -334699 -185602 -786014 -338334 -964153 -189495 -453642 -24534 -910743 -413567 -284925 -456538 -197071 -645359 -376818 -326086 -661838 -575470 -518095 -942005 -988188 -119233 -193194 -665011 -250404 -491140 -512950 -567247 -79671 -655904 -235233 -225596 -49253 -131629 -602879 -299113 -20649 -641027 -793202 -129610 -579454 -735906 -665396 -126560 -964144 -251029 -203345 -229514 -952888 -19690 -462760 -537988 -499427 -198225 -71996 -38675 -764198 -356590 -434366 -954985 -183306 -194063 -544002 -343401 -561100 -421221 -778820 -506484 -560984 -474961 -603666 -777762 -307007 -461259 -89736 -851180 -529776 -292523 -404121 -879133 -754985 -974867 -746234 -103022 -105082 -18228 -830501 -724047 -368525 -469945 -345008 …
Output: -334163145

Constraints:

1 <= k <= n <= 1777; -1000000 <= a[i] <= 1000.

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