let rec for_fold a b f v = if a >= b then v else for_fold (a+1) b f (f v a)
let _ = Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let sa = Array.init (n+1) (fun i -> if i = 0 then 0 else a.(i-1)) in
  for i = 1 to n do sa.(i) <- sa.(i) + sa.(i-1) done;
  let sp = Array.make (n+1) 0 in
  for i = 1 to n do sp.(i) <- max 0 a.(i-1) + sp.(i-1) done;

  for_fold 0 (n-k+1) (fun s i ->
    max s @@ sp.(i) + max 0 (sa.(i+k) - sa.(i)) + sp.(n) - sp.(i+k)) 0
  |> Printf.printf "%d\n"
