Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    let allsum = Array.make n 0 in
    let possum = Array.make n 0 in
    allsum.(0) <- a.(0);
    possum.(0) <- max a.(0) 0;
    for i = 1 to n - 1 do
        allsum.(i) <- allsum.(i - 1) + a.(i);
        possum.(i) <- possum.(i - 1) + max a.(i) 0
    done;
    let rec loop i acc =
        if i + k > n then acc else
            let score = possum.(i - 1) + max 0 (allsum.(i + k - 1) - allsum.(i - 1)) + possum.(n - 1) - possum.(i + k - 1)
            in
            loop (i + 1) (max acc score)
    in
    Printf.printf "%d\n" @@ loop 1 (max 0 allsum.(k - 1) + possum.(n - 1) - possum.(k - 1))
)