#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<long long>;
using vl = vector<long long>;
using pii = pair<long long, long long>;
using pll = pair<long long, long long>;
const long long DX[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0},
                DY[9] = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); ++i)
    os << *i << (i == end(v) - 1 ? "" : " ");
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); ++i) is >> *i;
  return is;
}
template <class T>
istream &operator>>(istream &is, pair<T, T> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(15) << fixed;
  }
} before_main_function;
signed main() {
  long long N, K;
  cin >> N >> K;
  vi a(N);
  cin >> a;
  long long ans = 0, last = -1;
  for (long long i = 0, i_len = (long long)(N - K); i < i_len; ++i) {
    if (a[i] > 0) {
      ans += a[i];
      last = i;
    }
  }
  long long sub1 = 0, sub2 = 0;
  for (long long i = N - K, i_len = (long long)(N); i < i_len; ++i) {
    if (i <= last + K)
      sub1 += a[i];
    else
      sub2 += a[i];
  }
  long long ans1 = ans, ans2 = ans;
  if (sub1 < 0) chmax(ans1, ans + sub2);
  if (sub1 + sub2 > 0) chmax(ans2, ans + sub1 + sub2);
  cout << max(ans1, ans2) << endl;
  return 0;
}
