import java.util.Scanner

/**
 * Created by sonetsuyoshi on 2015/12/16.
 */
object Main extends App {
  val sc = new Scanner(System.in)
  val (n, m) = (sc.nextInt, sc.nextInt)
  val a = Array.ofDim[Long](n)
  val b = Array.ofDim[Long](n)

  val s = Array.ofDim[Long](n + 1)
  val t = Array.ofDim[Long](n + 1)

  for(i <- 0 until n) {
    a(i) = sc.nextLong()
    b(i) = Math.max(0, a(i))

    t(i + 1) = t(i) + a(i)
    s(i + 1) = s(i) + b(i)
  }

  def partialSum(i: Int, j: Int, sum: Array[Long]):Long = {
    sum(j) - sum(i)
  }

  val ans = (for(i <- 0 to n - m) yield partialSum(0, i, s) + Math.max(partialSum(i, i + m, t), 0) + partialSum(i + m, n, s)).max
  println(ans)
}