#include <bits/stdc++.h>
using namespace std;
int n, m;
long long a[100005], b[100005], dis[100005], sum[100005];
int low[100005], up[100005];
int main() {
  while (~scanf("%d%d", &n, &m)) {
    dis[0] = 0;
    memset(sum, 0, sizeof sum);
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &a[i]);
      dis[i] = dis[i - 1] + a[i];
    }
    b[0] = 0;
    b[n + 1] = 0;
    memset(low, 0, sizeof low);
    memset(up, 0, sizeof up);
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &b[i]);
      sum[i] = sum[i - 1];
      if (b[i]) sum[i] += a[i];
      if (b[i - 1] == 0 && b[i] == 1)
        low[i] = i;
      else if (b[i])
        low[i] = low[i - 1];
    }
    for (int i = n; i >= 1; i--) {
      if (b[i + 1] == 0 && b[i] == 1)
        up[i] = i;
      else if (b[i])
        up[i] = up[i + 1];
    }
    long long ans = 0;
    for (int i = 1; i <= n - m + 1; i++) {
      int L = low[i - 1];
      int R = up[i + m];
      if (!L) L = i;
      if (!R) R = i + m - 1;
      ans = max(ans, sum[L - 1] + dis[R] - dis[L - 1] + sum[n] - sum[R]);
    }
    printf("%lld\n", ans);
  }
  return 0;
}
