{-# OPTIONS_GHC -O2 -optc-O2 #-}
module Main where

import Control.Applicative
import Data.Int
import Data.List

data Test = Test Int [Int64]

slidingSums :: Int -> [Int64] -> [Int64]
slidingSums k as = zipWith (-) (drop k ps) ps
    where ps = scanl (+) 0 as

prefixPositiveSums, suffixPositiveSums :: [Int64] -> [Int64]
prefixPositiveSums = scanl (\x y -> if y >= 0 then x + y else x) 0
suffixPositiveSums = scanr (\x y -> if x >= 0 then x + y else y) 0

solve :: Test -> Int64
solve (Test k as) = maximum $ zipWith3 add ss pps (drop k sps)
    where ss = map (max 0) $ slidingSums k as
          pps = prefixPositiveSums as
          sps = suffixPositiveSums as
          add x y z = x + y + z

test0 = Test 3 [-10, 10, -10, 10, -10]
test1 = Test 2 [10, -10, -10, 10]
test2 = Test 1 [-10]
test3 = Test 5 [5, -4, -5, -8, -4, 7, 2, -4, 0, 7]
runTests = map solve [test0, test1, test2, test3]

main :: IO ()
main = do
  [_, k] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  print . solve $ Test k as