#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    // Optimize standard I/O operations for competitive programming
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, k; 
    if (!(cin >> n >> k)) return 0;

    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    // Calculate prefix sums
    vector<ll> p(n);
    p[0] = a[0];
    for(int i = 1; i < n; i++) {
        p[i] = a[i] + p[i-1];
    }

    multiset<ll> u;
    u.insert(0); // Essential for subarrays starting at index 0

    ll final_max = -1e18; // Use a very small number for negative arrays

    for(int i = 0; i < n; i++) {
        // If the window size exceeds k, remove the oldest prefix sum
        if(i >= k) {
            ll val_to_remove = (i - k == 0) ? 0 : p[i - k - 1];
            u.erase(u.find(val_to_remove));
        }

        // The smallest prefix sum in the current window will yield the max subarray
        ll r = p[i] - *u.begin();
        final_max = max(final_max, r);

        // Insert the current prefix sum for future iterations
        u.insert(p[i]);
    }

    cout << final_max << "\n";
    
    return 0;
}