#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

template <typename T>
struct swag {
    struct node {
        T val, sum;
        node(const T &val, const T &sum) : val(val), sum(sum) {}
    };
    using F = function<T(T, T)>;
    F op;
    stack<node> front_stack, back_stack;
    swag(const F &op) : op(op) {}
    bool empty() const { return front_stack.empty() && back_stack.empty();}
    size_t size() const { return front_stack.size() + back_stack.size();}
    T fold() const {
        assert(!empty());
        if (front_stack.empty()) {
            return back_stack.top().sum;
        } else if (back_stack.empty()) {
            return front_stack.top().sum;
        } else {
            return op(front_stack.top().sum, back_stack.top().sum);
        }
    }
    void push(const T &x) {
        if (back_stack.empty()) {
            back_stack.emplace(x, x);
        } else {
            T s{op(back_stack.top().sum, x)};
            back_stack.emplace(x, s);
        }
    }
    void pop() {
        assert(!empty());
        if (front_stack.empty()) {
            front_stack.emplace(back_stack.top().val, back_stack.top().val);
            back_stack.pop();
            while (!back_stack.empty()) {
                T s{op(back_stack.top().val, front_stack.top().sum)};
                front_stack.emplace(back_stack.top().val, s);
                back_stack.pop();
            }
        }
        front_stack.pop();
    }
};

template <typename T>
struct fenwick_tree {
    int n, power; // min power s.t. n <= power && power = 2^k;
    vector<T> data;
    fenwick_tree(int n=0) : n(n), data(n+1) {
        power = 1;
        while (power < n) power <<= 1;
    }
    void add(int i, T x=1) {
        for (i++; i <= n; i += i&-i) data[i] += x;
    }
    // [0, i)
    T sum(int i) {
        T res = 0;
        for (; i; i -= i&-i) res += data[i];
        return res;
    }
    // [l, r)
    T sum(int l, int r) { return sum(r) - sum(l);} 
    // min x s.t. v0 + v1 + v2 + ... + vx　>= w
    int lower_bound(T w) {
        if (w <= 0) return 0;
        int x = 0;
        for (int i = power; i; i >>= 1) {
            if (i+x <= n && data[i+x] < w) {
                w -= data[i+x];
                x += i;
            }
        }
        return x;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    fenwick_tree<ll> ft(n);
    rep(i, n) if (a[i] > 0) ft.add(i, a[i]);
    auto f = [](ll a, ll b) { return a + b;};
    swag<ll> slide(f);
    const ll inf = 5e18;
    ll ans = -inf;
    rep(i, n) {
        slide.push(a[i]);
        if ((int)slide.size() == k) {
            ll sum = slide.fold();
            chmax(ans, ft.sum(0, i-k+1) + (sum > 0) * sum + ft.sum(i+1, n));
            slide.pop();
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6656