#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long

using namespace std;
using namespace __gnu_pbds;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
void solve() {
    int n, k; cin >> n >> k;

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

    int ans = 0;

    ordered_set st;

    int sm = 0;
    for (int i = 0; i < k; ++i) {
        st.insert(a[i] * mod + i);
        sm += a[i];
    }

    ans = k + sm;

    for (int i = k; i < n; ++i) {
        int val = *st.find_by_order(0);
        sm -= val / (int)mod;

        st.erase(val);

        st.insert(a[i] * mod + i);
        sm += a[i];

        ans = max(ans, i + 1 + sm);
    }

    cout << ans;
}

signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int tt = 1;
    while (tt--) {
        solve();
        cout << "\n";
    }
}