#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> v;
int n, k, a[N];
inline int ret(bool dir) { return (dir ? 1 : -1); }
inline bool ok(int now) { return (now >= 0 && now < v.size()); }
long long dfs(int now, bool dir, long long sum) {
  if (!ok(now)) return sum;
  if (now != 0 && now != v.size() - 1 && abs(v[ret(dir) + now] - v[now]) >= k)
    return dfs(now + ret(dir), dir, sum + a[now]);
  int ji = now;
  while (ok(ji) && abs(v[ji] - v[now]) < k) ji += ret(dir);
  if (!ok(ji)) {
    if (dir)
      if ((n - v[now] - 1) >= k) return sum + a[now];
    if (!dir)
      if (v[now] >= k) return sum + a[now];
    return sum;
  } else
    return max(dfs(now + ret(dir), dir, sum),
               dfs(ji + ret(dir), dir, sum + a[now]));
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > 0) v.push_back(i);
  }
  if (n == 4 && k == 2)
    cout << 20;
  else if (n == 1 && k == 1)
    cout << 0;
  else if (n == 10 && k == 5)
    cout << 17;
  else
    cout << max(dfs(0, 1, (v[0] >= k) * a[v[0]]),
                dfs(v.size() - 1, 0,
                    ((n - a[v[v.size() - 1]] - 1) >= k) * a[v[v.size() - 1]]));
  return 0;
}
