#include <bits/stdc++.h>

using namespace std;
mt19937 rnd(42);
using ll = long long;
using lll = __int128_t;
void solve() {
    ll n, k;
    cin >> n >> k;
    vector <ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    multiset <ll> se;
    ll su = 0;
    if (k == 1) {
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            ans = max(ans, a[i] + i + 1);
        }
        cout << ans;
        return;
    }
    for (int i = 0; i < k - 1; i++) {
        se.insert(a[i]);
        su += a[i];
    }
    ll ans = 0;
    for (int i = k - 1; i < n; i++) {
        ans = max(ans, su + a[i] + i + 1);
        if (*se.begin() < a[i]) {
            su += a[i] - *se.begin();
            se.erase(se.begin());
            se.insert(a[i]);
        }
    }
    cout << ans;
    cout << "\n";
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
/*
5 3
3 7 10 1 2
*/
