import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

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

    long solve() {
        long s;
        int colour;
        size_t end;
        foreach (i, a; as) {
            if (i == N-K) {
                long s1, s2, s3;
                foreach (j, b; as[i..$]) {
                    s1 += b;
                    if (colour != 0 || i+j >= end) s2 += b;
                    if (colour == 1 && i+j < end) s3 += b;
                }
                auto ss = max(s1, s2, s3);
                if (ss > 0) s += ss;
                break;
            } else if (a > 0 && colour == 0) {
                s += a;
                colour = 1;
                end = i + K;
            } else if (a < 0 && colour == 1) {
                colour = 0;
                end = i + K;
            } else if (end != 0 && i == end) {
                colour = 0;
                end = 0;
            }
        }
        return s;
    }

    auto s1 = solve();
    as = as.reverse.array;
    auto s2 = solve();
    writeln(max(s1, s2));
}