#include <bits/stdc++.h>
#define INF 10000000000000007
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    long a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    long acc[n + 1];
    acc[0] = 0;
    for (int i = 1; i <= n; i++) {
        acc[i] = acc[i - 1] + a[i - 1];
    }

    long max_acc = 0;
    int index = 0;
    for (int i = k; i <= n; i++) {
        if (max_acc < acc[i] - acc[i - k]) {
            max_acc = acc[i] - acc[i - k];
            index = i - k;
        }
    }
    long ans = 0;
    if (max_acc == 0) {
        long min_acc = INF;
        acc[0] = 0;
        for (int i = 1; i <= n; i++) {
            acc[i] = acc[i - 1] + max(0, a[i - 1]);
        }
        for (int i = k; i <= n; i++) {
            if (min_acc > acc[i] - acc[i - k]) {
                min_acc = acc[i] - acc[i - k];
                index = i - k;
            }
        }
    } else {
        ans = max_acc;
    }
    for (int i = 0; i < k; i++) {
        a[i + index] = 0;
    }

    for (int i = 0; i < n; i++) {
        if (a[i] > 0)
            ans += a[i];
    }
    cout << ans << endl;
    return 0;
}
