#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;


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

	int n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	ll ans = 0;
	multiset<ll> se;
	ll sumk = 0;
	for (int i = 0; i < k - 1; ++i) {
		se.insert(a[i]);
		sumk += a[i];
	}
	for (int i = k - 1; i < n; ++i) {
		ll cur = a[i] + (i + 1) + sumk;
		ans = max(ans, cur);
		if (*se.begin() < a[i]) {
			sumk -= *se.begin();
			se.erase(se.begin());
			sumk += a[i];
			se.insert(a[i]);
		}
	}
	cout << ans;

	return 0;
}