let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let sum = Array.make (n + 1) 0 in
  let pos = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    sum.(i + 1) <- as_.(i) + sum.(i);
    pos.(i + 1) <- max 0 as_.(i) + pos.(i)
  done;
  Printf.printf "%d\n" @@
    Array.fold_left max min_int @@
      Array.init (n - k + 1) @@ fun i ->
        pos.(i) + max 0 (sum.(i + k) - sum.(i)) + pos.(n) - pos.(i + k)
