#include <bits/stdc++.h>
using namespace std;
const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const long long MXLL = 4e18;
const int Sz = 1110111;
inline void Read_rap() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
inline void randomizer3000() {
  unsigned int seed;
  asm("rdtsc" : "=A"(seed));
  srand(seed);
}
void files(string problem) {
  if (fopen((problem + ".in").c_str(), "r")) {
    freopen((problem + ".in").c_str(), "r", stdin);
    freopen((problem + ".out").c_str(), "w", stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen(in, "r")) {
    freopen(in, "r", stdin);
  } else
    cerr << "Warning: Input file not found" << endl;
}
int n, k;
int a[Sz];
long long pref[Sz], p[Sz];
long long dp[Sz][2];
int main() {
  Read_rap();
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + a[i], p[i] = p[i - 1] + (a[i] > 0 ? a[i] : 0);
  long long ans = 0;
  for (int i = 1; i + k - 1 <= n; i++) {
    long long sum = p[n] - p[i + k - 1] + p[i - 1];
    sum += max(0ll, pref[i + k - 1] - pref[i]);
    ans = max(ans, sum);
  }
  cout << ans;
  return 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    if (i < k) {
      dp[i][1] = -MXLL;
    } else {
      static deque<pair<long long, int> > q;
      while (!q.empty() && q.front().second <= i - k) q.pop_front();
      dp[i][1] = max(dp[i - k][0], dp[i - k][1]) + pref[i] - pref[i - k];
      if (!q.empty()) dp[i][1] = max(dp[i][1], q.front().first + pref[i]);
      long long val = dp[i][1] - pref[i];
      while (!q.empty() && q.back().first > val) q.pop_back();
      q.push_back({val, i});
    }
  }
  cout << max(dp[n][1], dp[n][0]);
  return 0;
}
