#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long maxSubarraySumAtLeastK(const vector<long long>& a, int k) {
int n = a.size();
if (n < k) return 0;
// pmax[i] = maximum subarray sum ending at index "i"
vector<long long> pmax(n);
pmax[0] = a[0];
for (int i = 1; i < n; i++) {
pmax[i] = max(a[i], a[i] + pmax[i - 1]);
}
// kmax[i] = maximum subarray sum ending at index "i" such that size >= k
vector<long long> kmax(n, 0);
// 1. Calculate the sum of the first window of size 'k'
long long current_window_sum = 0;
for (int i = 0; i < k; i++) {
current_window_sum += a[i];
}
// Base case: The first valid subarray of at least size k ends at index k-1
kmax[k - 1] = current_window_sum;
// 2. Populate the rest of the kmax array using the max() function
for (int i = k; i < n; i++) {
// Shift the window of size 'k' by 1 step
current_window_sum = current_window_sum + a[i] - a[i - k];
// Compare taking only the current window vs. taking the current window + best prefix
kmax[i] = max(current_window_sum, current_window_sum + pmax[i - k]);
}
// 3. The answer is the maximum value in our kmax array
long long overall_max = kmax[k - 1];
for (int i = k; i < n; i++) {
overall_max = max(overall_max, kmax[i]);
}
// Return 0 if the answer is negative
return max(0LL, overall_max);
}
int main() {
// Fast I/O for Competitive Programming
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t; // Uncomment if there are multiple test cases
while (t--) {
int n, k;
if (!(cin >> n >> k)) break;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cout << maxSubarraySumAtLeastK(a, k) << "\n";
}
return 0;
}