let memoize n f =
  let dp = Hashtbl.create n in
  let rec get x =
    try Hashtbl.find dp x with
    | Not_found ->
        let result = f get x in
        Hashtbl.add dp x result;
        result in
  get

let () =
  let n, k = Scanf.scanf "%d %d\n" (fun n k -> n, k) in
  let as_ = Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in
  let sum = memoize (n - k + 1) (fun sum -> function
    | 0 -> Array.fold_left ( + ) 0 (Array.init k (fun i -> as_.(i)))
    | i -> sum (i - 1) - as_.(i - 1) + as_.(i - 1 + k)) in
  let pos = memoize (n - k + 1) (fun pos -> function
    | 0 -> Array.fold_left ( + ) 0 (Array.init k (fun i -> max 0 as_.(i)))
    | i -> pos (i - 1) - max 0 as_.(i - 1) + max 0 as_.(i - 1 + k)) in
  let positives = Array.fold_left ( + ) 0 (Array.map (max 0) as_) in
  Array.init (n - k + 1) (fun i -> max 0 (sum i) + positives - pos i)
  |> Array.fold_left max min_int
  |> Printf.printf "%d\n"