#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
  int t;
  edge(int _t) : t(_t) {}
};
bool use[100010];
vector<edge> te[100010];
vector<edge> fe[100010];
int d[100100];
long long rec(int num) {
  if (num == 0) return 0;
  return rec(num - 1) + num;
}
long long gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void Solve() {
  int n, k;
  cin >> n >> k;
  long long a[100010];
  long long r[100010];
  a[0] = 0;
  r[0] = 0;
  for (size_t i = 1; i <= n; i++) {
    cin >> a[i];
    r[i] = r[i - 1] + a[i];
  }
  long long dp[100010][2];
  for (size_t i = 0; i <= k; i++) {
    dp[i][0] = 0;
    dp[i][1] = r[i];
  }
  for (int i = k + 1; i <= n; i++) {
    long long f1 = max(dp[i - k][0], dp[i - k][1]);
    long long f2 = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][0] = max(f1, f2);
    long long br = r[i] - r[i - k];
    long long b11 = dp[i - k][1] + br;
    long long b1 = max(dp[i - k + 1][0] + br, b11);
    long long b2 = max(dp[i - 1][0] + a[i], dp[i - 1][1] + a[i]);
    dp[i][1] = max(b1, b2);
  }
  long long res = max(dp[n][1], dp[n][0]);
  cout << res << endl;
}
int main() {
  Solve();
  return 0;
}
