#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
const int mx = 2e5 + 5;
ll n, k, a[mx], b[mx], dp[mx], dp2[mx];
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    b[i] = b[i - 1] + a[i];
    if (a[i] >= 0) {
      if (i + k - 1 <= n)
        dp[i] = dp2[i - 1] + a[i];
      else if (i >= k) {
        dp[i] = dp2[i - k] + b[i] - b[i - k];
        if (i > k) dp[i] = max(dp[i], dp2[i - k - 1] + a[i]);
      }
    }
    dp[i] = max(dp[i], 0LL);
    dp2[i] = max(dp2[i - 1], dp[i]);
    ans = max(ans, dp2[i]);
  }
  cout << ans << "\n";
  return 0;
}
