#include <bits/stdc++.h>

#pragma GCC optimize("O3,Ofast,fast-math,unroll-loops")
#pragma GCC target("avx,avx2,fma,sse,sse2,sse3,sse4,sse4.1,sse4.2")

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long


//ordered_set
//ordered_set<int> A;
//A.find_by_order(1);
//A.order_of_key(1);

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int res = 0;
    int n, k;
    cin >> n >> k;
    ordered_set<int> A;
    vector<int>b;
    int x, bs = 0;
    int cnt_del = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        if (i>=k) {
            int cr = x+i+bs;
            res=max(res,cr);
        }
        if (i < k) {
            bs += x;
            A.insert(x);
        } else {
            if (x > *A.find_by_order(cnt_del)) {
                bs -= *A.find_by_order(cnt_del);
                //cout <<"First " << *A.find_by_order(cnt_del)<<"\n";
                bs += x;
//                for (int j = 0; j < A.size(); ++j) {
//                    cout << *A.find_by_order(j)<<" ";
//                }
//                cout<<"\n";
                A.insert(x);
                cnt_del++;
            }
        }
    }
    cout << res;
}
