#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  long long int arr[n], t[n], sum1[n], sum2[n], dp[n - k + 1], sum = 0, cp1[n],
                                                               cp2[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  sum1[0] = arr[0], sum2[n - 1] = arr[n - 1];
  for (int i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (int i = 1; i < n; i++) {
    sum1[i] = sum1[i - 1] + arr[i];
  }
  for (int i = n - 2; i >= 0; i--) {
    sum2[i] = sum2[i + 1] + arr[i];
  }
  for (int i = 0; i < n - k + 1; i++) {
    if (i == 0) {
      if (k != n)
        dp[i] = sum - sum2[i + k];
      else
        dp[i] = sum;
    } else if (i == n - k) {
      dp[i] = sum - sum1[i - 1];
    } else
      dp[i] = sum - sum1[i - 1] - sum2[i + k];
  }
  if (t[0] == 1) {
    cp1[0] = arr[0];
  } else
    cp1[0] = 0;
  if (t[n - 1] == 1) {
    cp2[n - 1] = arr[n - 1];
  } else
    cp2[n - 1] = 0;
  for (int i = 1; i < n; i++) {
    if (t[i] == 1)
      cp1[i] = cp1[i - 1] + arr[i];
    else
      cp1[i] = cp1[i - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    if (t[i] == 1)
      cp2[i] = cp2[i + 1] + arr[i];
    else
      cp2[i] = cp2[i + 1];
  }
  for (int i = 0; i < n - k + 1; i++) {
    if (i == 0) {
      if (n != k) dp[i] += (cp2[i + k]);
    } else if (i == n - k)
      dp[i] += (cp1[i - 1]);
    else
      dp[i] += (cp1[i - 1] + cp2[i + k]);
  }
  sort(dp, dp + n - k + 1);
  cout << dp[n - k];
  return 0;
}
