#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//using ll = int;
using ld = long double;
using ull = unsigned long long;
#define pb push_back
#define all(vec) vec.begin(), vec.end()
#define eb emplace_back
#ifdef LOCAL
#define deb(x) cout << #x << " = " << x << '\n'
#else
#define deb(x) 52
#endif
const ll inf = 1e9 + 11;
const long long INF = (long long)2e18 + 11;
const ll P = 73;
const ll MOD = 1e9 + 7;


mt19937 gen(52);


struct Treap {
    struct Node {
        ll x, y, sz, sm;
        Node *l, *r;

        Node(ll x = 0) : x(x) {
            y = gen();
            sm = x;
            sz = 1;
            l = nullptr, r = nullptr;
        }
    };

    typedef pair<Node*, Node*> Pair;

    ll vsize(Node *v) {
        return (v ? v->sz : 0);
    }

    ll vsum(Node *v) {
        return (v ? v->sm : 0);
    }

    void upd(Node *v) {
        v->sz = vsize(v->r) + vsize(v->l) + 1;
        v->sm = vsum(v->l) + vsum(v->r) + v->x;
    }

    Node *root = nullptr;

    Node* merge(Node *l, Node *r) {
        if (!l) {
            return r;
        }
        if (!r) {
            return l;
        }
        if (l->y > r->y) {
            l->r = merge(l->r, r);
            upd(l);
            return l;
        } else {
            r->l = merge(l, r->l);
            upd(r);
            return r;
        }
    }

    Pair split(Node *v, ll k) {
        if (!v) {
            return {nullptr, nullptr};
        }
        if (vsize(v->l) + 1 <= k) {
            Pair q = split(v->r, k - vsize(v->l) - 1);
            v->r = q.first;
            upd(v);
            return {v, q.second};
        } else {
            Pair q = split(v->l, k);
            v->l = q.second;
            upd(v);
            return {q.first, v};
        }
    }

    Pair split_val(Node *v, ll k) {
        if (!v) {
            return {nullptr, nullptr};
        }
        if (v->x <= k) {
            Pair q = split_val(v->r, k);
            v->r = q.first;
            upd(v);
            return {v, q.second};
        } else {
            Pair q = split_val(v->l, k);
            v->l = q.second;
            upd(v);
            return {q.first, v};
        }
    }

    void insert(ll x) {
        Pair q = split_val(root, x);
        root = merge(merge(q.first, new Node(x)), q.second);
    }

    ll get(ll k) {
        Pair q = split(root, vsize(root) - k);
        ll ans = vsum(q.second);
        root = merge(q.first, q.second);
        return ans;
    }
};


void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    Treap treap;
    ll ans = 0;
    for (ll i = 0; i < k - 1; ++i) {
        treap.insert(a[i]);
    }
    for (ll i = k - 1; i < n; ++i) {
        ans = max(ans, treap.get(k - 1) + a[i] + i + 1);
        treap.insert(a[i]);
    }
    cout << ans;
}


int main() {
#ifdef LOCAL
    freopen("C:/work/untitled/input.txt", "r", stdin);
    freopen("C:/work/untitled/output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll cfmode = 0;
    ll tc = 1;
    if (cfmode) {
        cin >> tc;
    }
    while (tc--) {
        solve();
        if (tc) {
            cout << '\n';
        }
    }
}