CT55757

Smith Counts the segments

MediumL5 · Recursion RenegadeAcceptance: 0.0%XP: 60

The harbor bell rings at the island market of Coralcove; Smith weighs the day's segments manifests and starts the calculations. 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 <= 3681; -1000000 <= a[i] <= 1000.

Example 1:

Input: 2236 1447 -456285 -685157 -933898 -642610 -938985 -820147 -75013 -541782 -584904 -30734 -388857 -777546 -191502 -772813 -358770 -341248 -216279 -133995 -726586 -414835 -327972 -58463 -662293 -596001 -997292 -223311 -241322 -548879 -179183 -683747 -24361 -248886 -772380 -383380 -611815 -195126 -140224 -580625 -223105 -306079 -157726 -621457 -935602 -440898 -975759 -190853 -46032 -931920 -510665 -709708 -515901 -713959 -329670 -541411 -389762 -220848 -711549 -781998 -292153 -709271 -551810 -504253 -545641 -655536 -319304 -894543 -783703 -986786 -148833 -93487 -186512 -36122 -129087 -117076 -146697 -791126 -395325 -953558 -126029 -861449 -528938 -274618 -316373 -22464 -307132 -177176 -274564 -578504 -883604 -844598 -334455 -460617 -302433 -436933 -313723 -916929 -331404 -469853 -290092 -64696…
Output: -705191127

Example 2:

Input: 3239 2705 -208648 -230704 -890277 -705982 -689022 -786547 -438304 -393163 -876305 -912522 -268465 -140682 -925392 -586089 -541340 -360112 -178845 -767743 -747044 -369 -964574 -926302 -386917 -279839 -33782 -23417 -213092 -861278 -308255 -847888 -669182 -789837 -475025 -969503 -719392 -373262 -246552 -457472 -316815 -72623 -606455 -865873 -550343 -148063 -225068 -286244 -133738 -862850 -442944 -910914 -783970 -88899 -68743 -430912 -528843 -726310 -185320 -168399 -921130 -914313 -939267 -834758 -434591 -2732 -21261 -175729 -693125 -8898 -237001 -50232 -607119 -945333 -130041 -793803 -977706 -913985 -368804 -716229 -948406 -892698 -747201 -459022 -425755 -371176 -715859 -242176 -49372 -783600 -193643 -807493 -331206 -646390 -737933 -834925 -721776 -925162 -529164 -378103 -370397 -43240 -83544…
Output: -1371739690

Example 3:

Input: 184 138 -149291 -545039 -702146 -223377 -893834 -897869 -703757 -769448 -92651 -196120 -154831 -92051 -645957 -786946 -356262 -447564 -749800 -950412 -907470 -472358 -49558 -869939 -999626 -919061 -368036 -240071 -621578 -217711 -384543 -807627 -377299 -568942 -734404 -462887 -682270 -772057 -644250 -164309 -543223 -23706 -503265 -289842 -484789 -60384 -739757 -737444 -942576 -887700 -72510 -105123 -628368 -618537 -687406 -558157 -375123 -632651 -358528 -277469 -832694 -134455 -246447 -221319 -312650 -269033 -463342 -4995 -651825 -476231 -478658 -813325 -782322 -132161 -114467 -877574 -101860 -842529 -560552 -914179 -448348 -633628 -895112 -176464 -203347 -105884 -9207 -834574 -297724 -692608 -916699 -760331 -788217 -871391 -788074 -248100 -895154 -596632 -380593 -256037 -322087 -194909 -9…
Output: -68221430

Constraints:

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

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