#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template <typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  cout << '(' << p.first << ' ' << p.second << ')';
  return os;
}
template <typename T>
void dpite(T a, T b) {
  return;
}
template <typename T>
void pite(T a, T b) {
  for (T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite;
  cout << '\n';
}
template <typename T>
bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
void ios_init() {
  ios::sync_with_stdio(false);
  cin.tie(0);
}
int main() {
  ios_init();
  int n, k;
  while (cin >> n >> k) {
    vector<int> a(n);
    for (int i = (0); i < (n); ++i) cin >> a[i];
    if (n == k) {
      long long int sum = 0;
      for (int i = (0); i < (n); ++i) {
        sum += a[i];
      }
      if (sum > 0)
        cout << sum << '\n';
      else
        cout << 0 << '\n';
      continue;
    }
    long long int sum = 0;
    int p = 0;
    for (int i = (0); i < (n - (k + 1)); ++i) {
      if (a[i] > 0) {
        sum += a[i];
        p = i;
      }
    }
    true;
    long long int t = sum;
    long long int s = 0;
    for (int i = (n)-1; i >= (p + k); i--) {
      s += a[i];
      true;
      { t = max(t, sum + s); }
    }
    long long int ans = t;
    sum = 0;
    p = n;
    for (int i = (n)-1; i >= (k - 1); i--) {
      if (a[i] > 0) {
        sum += a[i];
        p = i;
      }
    }
    true;
    t = sum;
    s = 0;
    for (int i = (0); i < (p - k); ++i) {
      s += a[i];
      { t = max(t, sum + s); }
    }
    true;
    true;
    cout << max(ans, sum) << '\n';
  }
  return 0;
}
