#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5;
int N, K;
int A[MAX_N];
long long dp[MAX_N + 1], sum[MAX_N + 1];
int main() {
  cin >> N >> K;
  for (int i = (0); i < (N); i++) {
    cin >> A[i];
  }
  for (int i = (0); i < (N); i++) {
    sum[i + 1] = sum[i] + A[i];
  }
  for (int i = (K); i < (N + 1); i++) {
    dp[i] = dp[i - 1];
    dp[i] = max(dp[i], sum[i] - sum[i - K] + dp[i - K]);
    if (i > K) {
      dp[i] = max(dp[i], A[i - 1] + dp[i - 1]);
      dp[i] = max(dp[i], A[i - K - 1] + dp[i - K - 1]);
    }
  }
  long long ans = dp[N];
  reverse(A, A + N);
  for (int i = (0); i < (N); i++) {
    sum[i + 1] = sum[i] + A[i];
  }
  for (int i = (K); i < (N + 1); i++) {
    dp[i] = dp[i - 1];
    dp[i] = max(dp[i], sum[i] - sum[i - K] + dp[i - K]);
    if (i > K) {
      dp[i] = max(dp[i], A[i - 1] + dp[i - 1]);
      dp[i] = max(dp[i], A[i - K - 1] + dp[i - K - 1]);
    }
  }
  ans = max(ans, dp[N]);
  cout << ans << endl;
  return 0;
}
