#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

template<typename T, typename S>
istream& operator >> (istream& is, pair<T, S>& p) {
    is >> p.first >> p.second;
    return is;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v) {
    for (auto& x : v) {
        os << x << " ";
    }
    os << "\n";
    return os;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n, k;
    cin >> n >> k;
    vector<int64_t> a(n);
    cin >> a;
    vector<int64_t> p(n + 1, 0), pp(n + 1, 0), sp(n + 1, 0);
    for (int i = 1; i <= n; ++i) p[i] = p[i - 1] + a[i - 1];
    for (int i = 1; i <= n; ++i) {
        pp[i] = pp[i - 1] + max(a[i - 1], 0ll);
        sp[i] = sp[i - 1] + max(a[n - i], 0ll);
    }
    // cout << pp << sp << endl;
    int64_t max_ans = 0;
    for (int ks = 0; ks + k <= n; ++ks) {
        // cout << ks << " " << pp[ks] << " " << sp[n - ks - k] << " " << p[ks + k] - p[ks] << endl;
        max_ans = max(max_ans, pp[ks] + sp[n - ks - k] + max(0ll, p[ks + k] - p[ks]));
    }
    cout << max_ans;

}
