#include <bits/stdc++.h>

using namespace std;
using ll = long long int;
using ull = unsigned long long int;

#define all(x) (x).begin(), (x).end()
#define rall(X) (x).rbegin(), (x).rend()

void solve()
{
    int n, k;
    cin >> n >> k;

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

    multiset<ll> st;
    ll s = 0;
    for (int i = 0; i < k - 1; i++)
    {
        st.insert(a[i]);
        s += a[i];
    }
    
    ll ans = LLONG_MIN;
    for (int i = k - 1; i < n; i++)
    {
        ans = max(ans, s + a[i] + i + 1);
        st.insert(a[i]);
        s += a[i];
        s -= *st.begin();
        st.erase(st.begin());
    }
    cout << ans << '\n';
}

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

    int t;
#ifdef LOCAL
    freopen("C:/work/Day 1/in.txt", "r", stdin);
    freopen("C:/work/Day 1/out.txt", "w", stdout);
    cin >> t;
#else
    t = 1;
#endif

    while (t--)
        solve();
    return 0;
}
