#include <bits/stdc++.h>
using namespace std;
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
const long long MAXN = 3e5 + 123;
const long double EPS = 1e-12;
const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
long long n, k, ans, a[MAXN], p[MAXN];
void solve() {
  cin >> n >> k;
  if (n >= k * 2) {
    for (int i = 1, x; i <= n; ++i) {
      cin >> x;
      ans += x * (x > 0);
    }
    cout << ans;
  } else {
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 0, sum = 0; i <= n - k; ++i) {
      sum += a[i];
      p[i] = sum;
    }
    for (int i = n, sum = 0; i >= k; --i) {
      sum += a[i];
      p[n - i] += sum;
      ans = max(p[n - 1], ans);
    }
    cout << ans;
  }
}
int main() {
  faster();
  int T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
