#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3e5 + 10;
void solve() {
int n, k;
cin >> n >> k;
vector<int>a(2 * n + 1, 0);
int mx = -2e9;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
a[i] += a[i - 1];//前缀和
}
for (int l = 1, r = 1; r <= n; r++) {
int res = a[r] - a[l - 1];
mx = max(mx, res);
if (res < 0 && l < r) {//区间和为负数就把l往r移动
while (l <= r && res < 0) {
res = a[r] - a[l - 1];
mx = max(mx, res);
l++;
}
}
if (a[l] - a[l - 1] < 0 && l < r) {//如果l位于负数就往r移动
while (a[l] - a[l - 1] < 0 && l <= r) {
l++;
res = a[r] - a[l - 1];
mx = max(mx, res);
}
}
if (r - l + 1 >= k) {
l++;
res = a[r] - a[l - 1];
mx = max(mx, res);
}
mx = max(mx, res);
if (r == n) {
while (l < r) {
l++;
res = a[r] - a[l - 1];
mx = max(mx, res);
}
}
}
cout << mx;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--)
solve();
return 0;
}