import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1];
    auto A = readln.split.map!(to!long);

    long positive = A[0..K].map!(a => a >= 0).sum;
    long pos_max = positive, pos_min = positive;
    foreach (i; 0..N-K) {
        positive += A[i+K] >= 0 ? 1 : -1;
        pos_max = max(pos_max, positive);
        pos_min = min(pos_min, positive);
    }
    if (pos_max == K || pos_min == 0) {
        A.map!(a => max(a, 0)).sum.writeln;
        return;
    }

    long section = A[0..K].sum;
    long section_max = section;
    Tuple!(int, int) section_max_i = tuple(0, K-1);
    long section_max_a = K == 1 ? A[0] : A[0..K].reduce!(max);
    foreach (i; 0..N-K) {
        section = section - A[i] + A[i+K];
        if (section_max == section) {
            section_max_i = tuple(i+1, i+K);
            section_max_a = K == 1 ? A[i+1] : A[i+1..i+K].reduce!(max);
        }
        else if (section > section_max) {
            section_max = section;
            section_max_i = tuple(i+1, i+K);
            section_max_a = K == 1 ? A[i+1] : A[i+1..i+K].reduce!(max);
        }
    }

    long ans;
    if (section_max >= 0) {
        ans = section_max;
        foreach (i; 0..N)
            if (i < section_max_i[0] || i > section_max_i[1])
                ans += max(A[i], 0);
    }
    else {
        long ans1 = 0, ans2 = 0;
        foreach (i; 0..N-K) {
            ans1 += max(A[i], 0);
            ans2 += max(A[N-i-1], 0);
        }
        ans = max(ans1, ans2);
    }

    ans.writeln;
}
