import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args){
                  Scanner s=new Scanner(System.in);
                  int n=s.nextInt();int k=s.nextInt();
                  int m=n;
                  int [] a=new int[n];int [] awk=new int[n];int l=0;
                  while(m-->0){
                   a[l]=s.nextInt();l++;
                  }
                  l=0;
                  while(n-->0){
                   awk[l]=s.nextInt();l++;
                  }int sum=0;int max=Integer.MIN_VALUE;int f=1;
                  for(int i=0;i<a.length;i++){
                      if(i==k) break;
                      else{if(awk[i]==0) f=1;
                         sum+=a[i];
                      }
                  }//System.out.println(sum);
                  if(f==1) max=sum;
                  int j=k;int si=-1;
                  for(int i=0;i<a.length-k;i++){
                    sum=sum-a[i]+a[j];
                    if(sum>max&&(awk[i+1]==0||awk[j++]==0)){
                       max=sum;si=i+1;
                    }
                  }//System.out.println(max);
                  int flag=0;int ans=0;
                  for(int i=0;i<a.length;i++){
                    if(i==si){
                       flag=1;
                    }
                    else if(i==si+k) flag=0;
                    if(flag==0&&awk[i]==1)
                       ans+=a[i];
                  }
                  if(max!=Integer.MIN_VALUE)
                    System.out.println(ans+max);
                    else System.out.println(ans);
  }
}


import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args){
                  Scanner s=new Scanner(System.in);
                  int n=s.nextInt();int k=s.nextInt();
                  int m=n;
                  int [] a=new int[n];int [] awk=new int[n];int l=0;
                  while(m-->0){
                   a[l]=s.nextInt();l++;
                  }
                  l=0;
                  while(n-->0){
                   awk[l]=s.nextInt();l++;
                  }long sum=0;long max=Long.MIN_VALUE;int f=1;
                  for(int i=0;i<a.length;i++){
                      if(i==k) break;
                      else{if(awk[i]==0)
                         sum+=a[i];
                      }
                  }//System.out.println(sum);
                   max=sum;
                  int j=k;int si=-1;
                  for(int i=0;i<a.length-k;i++){
                    if(awk[i]==0&&awk[j]==0)
                    sum=sum-a[i]+a[j];
                    else if(awk[i]==1&&awk[j]==0) sum=sum+a[j];
                    j++;
                    if(sum>max){
                       max=sum;si=i+1;
                    }
                  }//System.out.println(max);
                  int flag=0;long ans=0;
                  for(int i=0;i<a.length;i++){

                    if(awk[i]==1)
                       ans+=a[i];
                  }
                  if(max!=Integer.MIN_VALUE)
                    System.out.println(ans+max);
                    else System.out.println(ans);
  }
}


import java.io.*;
import java.util.*;
public class Main{
  public static void main(String[] args){
                  Scanner s=new Scanner(System.in);
                  int n=s.nextInt();int k=s.nextInt();
                  int m=n;
                  int [] a=new int[n];int [] awk=new int[n];int l=0;
                  while(m-->0){
                   a[l]=s.nextInt();l++;
                  }
                  l=0;
                  while(n-->0){
                   awk[l]=s.nextInt();l++;
                  }long sum=0;long max=Long.MIN_VALUE;int f=1;
                  for(int i=0;i<a.length;i++){
                      if(i==k) break;
                      else{if(awk[i]==0)
                         sum+=a[i];
                      }
                  }//System.out.println(sum);
                   max=sum;
                  int j=k;int si=-1;
                  for(int i=0;i<a.length-k;i++){
                    if(awk[i]==0&&awk[j]==0)
                    sum=sum-a[i]+a[j];
                    else if(awk[i]==1&&awk[j]==0) sum=sum+a[j];
                    else if(awk[i]==0&&awk[j]==1) sum=sum-a[i];
                    j++;
                    if(sum>max){
                       max=sum;si=i+1;
                    }
                  }//System.out.println(max);
                  int flag=0;long ans=0;
                  for(int i=0;i<a.length;i++){

                    if(awk[i]==1)
                       ans+=a[i];
                  }
                  if(max!=Integer.MIN_VALUE)
                    System.out.println(ans+max);
                    else System.out.println(ans);
  }
}


import java.util.Scanner;

public class CFLectureSleep {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int[] a = new int[n];
		int[] t = new int[n];
		int[] act = new int[n];
		int maxChange = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		for(int i = 0; i < n; i++) {
			t[i] = Math.abs(scanner.nextInt()-1);
			act[i] = Math.abs(t[i]-1);
			if(i < k) {
				maxChange += a[i]*t[i];
			}
		}
		int maxIndex = 0;
		for(int i = 1; i < n-k+1; i++) {
			int temp = maxChange - a[i-1]*t[i-1] + a[i+k-1]*t[i+k-1];
			if(temp > maxChange) {
				maxChange = temp;
				maxIndex = i;
			}
		}
		for(int i = maxIndex; i <= maxIndex+k-1; i++) {
			act[i] = 1;
		}
		int result = 0;
		for(int i = 0; i < n; i++) {
			result += a[i]*act[i];
		}
		System.out.println(result);
		scanner.close();

	}

}


import java.util.Scanner;

public class CFLectureSleep {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int[] a = new int[n];
		int[] t = new int[n];
		int[] act = new int[n];
		int maxChange = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		for(int i = 0; i < n; i++) {
			t[i] = Math.abs(scanner.nextInt()-1);
			act[i] = Math.abs(t[i]-1);
			if(i < k) {
				maxChange += a[i]*t[i];
			}
		}
		int maxIndex = 0;
		int temp = maxChange;
		for(int i = 1; i < n-k+1; i++) {
			temp = temp - a[i-1]*t[i-1] + a[i+k-1]*t[i+k-1];
			if(temp > maxChange) {
				maxChange = temp;
				maxIndex = i;
			}
		}
		for(int i = maxIndex; i <= maxIndex+k-1; i++) {
			act[i] = 1;
		}
		int result = 0;
		for(int i = 0; i < n; i++) {
			result += a[i]*act[i];
		}
		System.out.println(result);
		scanner.close();

	}

}


import java.util.Scanner;

public class CFLectureSleep {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int k = scanner.nextInt();
		int[] a = new int[n];
		int[] t = new int[n];
		int[] act = new int[n];
		int maxChange = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		for(int i = 0; i < n; i++) {
			t[i] = Math.abs(scanner.nextInt()-1);
			act[i] = Math.abs(t[i]-1);
			if(i < k) {
				maxChange += a[i]*t[i];
			}
		}
		int maxIndex = 0;
		for(int i = 1; i < n-k+1; i++) {
			int temp = maxChange - a[i-1]*t[i-1] + a[i+k-1]*t[i+k-1];
			if(temp > maxChange) {
				maxChange = temp;
				maxIndex = i;
			}
		}
		for(int i = maxIndex; i <= maxIndex+k-1; i++) {
			act[i] = 1;
		}
		int result = 0;
		for(int i = 0; i < n; i++) {
			result += a[i]*act[i];
		}
		System.out.println(maxIndex);
		scanner.close();

	}

}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;

public class j8 implements Runnable {

	public void run(){
		InputReader in =  new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		int k=in.nextInt();
		int[] a=new int[n+1];

		for(int i=1;i<=n;i++)
			a[i]=in.nextInt();

		int[] t=new int[n+1];
		for(int i=1;i<=n;i++)
			t[i]=in.nextInt();

		long sum=0;
		long ksum=0;
		long k1=0;
		long max=0;

		for(int i=1;i<=n;i++)
		{
			if(t[i]==1)
				sum+=a[i];

		}

		int j=-1;
		for(int i=1;i<=n;i++)
		{
			if(t[i]==0)
			{
				j=i;
				break;
			}
		}

		for(int i=j;i<j+k && i<=n;i++)
		{
			if(t[i]==0)
				ksum+=a[i];
		}

		max=Long.max(max, ksum+sum);

		for(int i=j+k;i<=n;i++)
		{
			if(t[i]==0)
			{
				if(t[j]==0)
					ksum-=a[j];
			 ksum+=a[i];
			}

			j++;

			max=Long.max(max, ksum+sum);
		}

		w.println(max);
		w.close();

	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new j8(),"j8",1<<26).start();
	}
 }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.TreeSet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.lang.Math;
import java.math.BigInteger;

public class j7 implements Runnable {

	public void run(){
		InputReader in =  new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		int k=in.nextInt();
		int[] a=new int[n+1];

		for(int i=1;i<=n;i++)
			a[i]=in.nextInt();

		int[] t=new int[n+1];
		for(int i=1;i<=n;i++)
			t[i]=in.nextInt();

		// lol hu nbdo 6u...
		long sum=0;
		long max=0;
		long pre[]=new long[n+1];

		for(int i=1;i<=n;i++)
		{
			if(t[i]==1)
			{
				sum+=a[i];
				a[i]=0;
			}
			pre[i]=pre[i-1]+a[i];
		}

		for(int i=1;i<=n-k+1;i++)
		{
			max=Long.max(max,pre[i+k-1]-pre[i-1]);
		}

		w.println(max+sum);
		w.close();

	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new j7(),"j7",1<<26).start();
	}
 }


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;

public class j8 implements Runnable {

	public void run(){
		InputReader in =  new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);
		int n=in.nextInt();
		int k=in.nextInt();
		int[] a=new int[n+1];

		for(int i=1;i<=n;i++)
			a[i]=in.nextInt();

		int[] t=new int[n+1];
		for(int i=1;i<=n;i++)
			t[i]=in.nextInt();

		long sum=0;
		long ksum=0;
		long k1=0;
		long max=0;

		for(int i=1;i<=n;i++)
		{
			if(t[i]==1)
				sum+=a[i];

		}

		int j=-1;
		for(int i=1;i<=n;i++)
		{
			if(t[i]==0)
			{
				j=i;
				break;
			}
		}

		for(int i=j;i<j+k && i<=n;i++)
		{
			if(t[i]==0)
				ksum+=a[i];
		}

		max=Long.max(max, ksum+sum);

		for(int i=j+k;i<=n;i++)
		{
			if(t[i]==0)
			{
				if(t[j]==0)
					ksum-=a[j];
			 ksum+=a[i];
			}

			j++;

			max=Long.max(max, ksum+sum);

			if(j==n+k-1)
				break;
		}

		w.println(max);
		w.close();

	}

	static class InputReader {

		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int read()
		{
			if (numChars==-1)
				throw new InputMismatchException();

			if (curChar >= numChars)
			{
				curChar = 0;
				try
				{
					numChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}

				if(numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public String nextLine()
		{
			BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
			String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
		}
		public int nextInt()
		{
			int c = read();

			while(isSpaceChar(c))
				c = read();

			int sgn = 1;

			if (c == '-')
			{
				sgn = -1;
				c = read();
			}

			int res = 0;
			do
			{
				if(c<'0'||c>'9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));

			return res * sgn;
		}

		public long nextLong()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			long res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			while (!isSpaceChar(c));
				return res * sgn;
		}

		public double nextDouble()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = read();
			}
			double res = 0;
			while (!isSpaceChar(c) && c != '.')
			{
				if (c == 'e' || c == 'E')
					return res * Math.pow(10, nextInt());
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = read();
			}
			if (c == '.')
			{
				c = read();
				double m = 1;
				while (!isSpaceChar(c))
				{
					if (c == 'e' || c == 'E')
						return res * Math.pow(10, nextInt());
					if (c < '0' || c > '9')
						throw new InputMismatchException();
					m /= 10;
					res += (c - '0') * m;
					c = read();
				}
			}
			return res * sgn;
		}

		public String readString()
		{
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = read();
			}
			while (!isSpaceChar(c));

			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String next()
		{
			return readString();
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}

	public static void main(String args[]) throws Exception
	{
		new Thread(null, new j8(),"j8",1<<26).start();
	}
 }


import java.util.Scanner;
public class newB {
	static long[] arr;
	static boolean[] woke;
	static int n, k;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		arr = new long[n];

		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}

		woke = new boolean[n];
		long tot = 0, rSum = 0, max = 0;
		for(int i = 0; i < n; i++){
			if(sc.nextInt() == 1){
				woke[i] = true;
				tot += arr[i];
			}
			else{
				rSum += arr[i];
				if(i < k) continue;
				if(!woke[i - k]) rSum -= arr[i - k];
			}
			if(rSum > max) max = rSum;
		}

		System.out.println(tot + max);
	}
}


import java.util.Scanner;
public class B {
	static int[] theorems;
	static int n, k;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		theorems = new int[n];
		BIT ideal = new BIT(n);
		for(int i = 0; i < n; i++){
			int in = sc.nextInt();
			theorems[i] = in;
			ideal.update(i, in);
		}

		int maxI = -1;
		long maxDiff = 0;
		BIT real = new BIT(n);
		for(int i = 0; i < n; i++){
			if(sc.nextInt() == 1){
				real.update(i, theorems[i]);
			}
			long best = ideal.sum(i) - ideal.sum(i - k);
//			System.out.println(best);
			long sub = real.sum(i) - real.sum(i - k);
//			System.out.println(sub);
			if(best - sub > maxDiff){
				maxDiff = best - sub;
				maxI = i;
//				System.out.println(maxDiff + " " + maxI);
			}
		}

		long out = real.sum(maxI - k);
		out += ideal.sum(maxI) - ideal.sum(maxI - k);
		if(maxI != n - 1) out += real.sum(n - 1) - real.sum(maxI + 1);
		System.out.println(out);
	}
}
class BIT{
	int n;
	long[] arr;
	BIT(int nIn){
		n = nIn;
		arr = new long[n + 1];
	}
	void update(int i, int val){
		i++;
		while(i <= n){
			arr[i] += val;
			i += Integer.lowestOneBit(i);
		}
	}
	long sum(int i){
		i++;
		long out = 0;
		while(i > 0){
			out += arr[i];
			i -= Integer.lowestOneBit(i);
		}
		return out;
	}
}


import java.util.Scanner;
public class newB {
	static int[] arr;
	static boolean[] woke;
	static int n, k;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		arr = new int[n];

		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}

		woke = new boolean[n];
		long tot = 0, rSum = 0, max = 0;
		for(int i = 0; i < n; i++){
			if(sc.nextInt() == 1){
				woke[i] = true;
				tot += arr[i];
			}
			else{
				if(i >= k && !woke[i - k]) rSum -= arr[i - k];
				rSum += arr[i];
			}
			if(rSum > max) max = rSum;
		}

		System.out.println(tot + max);
	}
}


import java.util.Scanner;
public class newB {
	static long[] arr;
	static boolean[] woke;
	static int n, k;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		k = sc.nextInt();
		arr = new long[n];

		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}

		woke = new boolean[n];
		long tot = 0, rSum = 0, max = 0;
		for(int i = 0; i < n; i++){
			if(sc.nextInt() == 1){
				woke[i] = true;
				tot += arr[i];
			}
			else{
				rSum += arr[i];
			}
			if(i >= k && !woke[i - k]) rSum -= arr[i - k];
			max = Math.max(max, rSum);
		}

		System.out.println(tot + max);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class lecturesleep {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(reader.readLine());
		int[] theorems = new int[n];
		for (int i = 0; i < n; i++) {
			theorems[i] = Integer.parseInt(st.nextToken());
		}
		int[] mishka = new int[n];
		long sum = 0;
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			mishka[i] = Integer.parseInt(st.nextToken());
			if (mishka[i] == 1) {
				sum = sum + theorems[i];
			}
		}
		long max = -1;
		for (int i = 0; i < n - k + 1; i++) {
			long s = 0;
			for (int j = i; j < i + k; j++) {
				if (mishka[j] != 1) {
					s = s + theorems[j];
				}
			}
			if (s > max) {
				max = s;
			}
		}
		System.out.println(max + sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class lecturesleep {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(reader.readLine());
		int[] theorems = new int[n];
		for (int i = 0; i < n; i++) {
			theorems[i] = Integer.parseInt(st.nextToken());
		}
		int[] mishka = new int[n];
		long sum = 0;
		long lol = 0;
		long[] mcs = new long[n];
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			mishka[i] = Integer.parseInt(st.nextToken());
			if (mishka[i] == 1) {
				sum = sum + theorems[i];
			} else {
				lol = lol + theorems[i];
			}
			mcs[i] = lol;
		}
		long max = mcs[k - 1];
		for (int i = k; i < n; i++) {
			if ( (mcs[i] - mcs[i - k]) > max) {
				max = mcs[i] - mcs[i - k];
			}
		}
		System.out.println(max + sum);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class lecturesleep {
	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(reader.readLine());
		int[] theorems = new int[n];
		for (int i = 0; i < n; i++) {
			theorems[i] = Integer.parseInt(st.nextToken());
		}
		int[] mishka = new int[n];
		st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			mishka[i] = Integer.parseInt(st.nextToken());
		}
		long sum = 0;
		for (int i = 0; i < n; i++) {
			if (mishka[i] == 1) {
				sum = sum + theorems[i];
			}
		}
		long max = -1;
		for (int i = 0; i < n - k + 1; i++) {
			long s = 0;
			for (int j = i; j < i + k; j++) {
				if (mishka[j] != 1) {
					s = s + theorems[j];
				}
			}
			if (s > max) {
				max = s;
			}
		}
		System.out.println(max + sum);
	}
}


import java.util.ArrayList;
import java.util.Scanner;

public class lecture_sleep {
    public static void main(String[] args) {
//        Scanner in = new Scanner(new File("lecture_sleep.in"));
        Scanner in = new Scanner(System.in);
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        int[] theorems = new int[n];
        ArrayList<Integer> zeros = new ArrayList<>();
        boolean[] awake = new boolean[n];
        int def = 0;
        for (int i=0;i<n;i++) {
            theorems[i] = in.nextInt();
        }
        for (int i=0;i<n;i++) {
            awake[i] = in.nextInt()==1;
            if (!awake[i]) zeros.add(i);
            else def += theorems[i];
        }
        int[] sums = new int[n];
        in.close();
        if (!awake[0]) sums[0] = theorems[0];
        for (int i=1;i<n;i++) {
            sums[i] = sums[i-1] + ((awake[i]) ? 0: theorems[i]);
        }
        int max = sums[k-1];
        for (int i : zeros) {
            if (i==0 || i>n-k) continue;
            int sum = sums[i+k-1]-sums[i-1];
            if (sum>max) {
                max = sum;
            }
        }
        System.out.println(max+def);
    }
}


import java.util.Scanner;

public class lecture_sleep {
    public static void main(String[] args) {
//        Scanner in = new Scanner(new File("lecture_sleep.in"));
        Scanner in = new Scanner(System.in);
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        int[] theorems = new int[n];
        boolean[] awake = new boolean[n];
        int def = 0;
        for (int i=0;i<n;i++) {
            theorems[i] = in.nextInt();
        }
        for (int i=0;i<n;i++) {
            awake[i] = in.nextInt()==1;
            if (awake[i]) def += theorems[i];
        }
        int[] sums = new int[n];
        in.close();
        if (!awake[0]) sums[0] = theorems[0];
        for (int i=1;i<n;i++) {
            sums[i] = sums[i-1] + ((awake[i]) ? 0: theorems[i]);
        }
        int max = sums[k-1];
        for (int i=1;i<n-k+1;i++) {
            int sum = sums[i+k-1]-sums[i-1];
            if (sum>max) {
                max = sum;
            }
        }
        System.out.println(max+def);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class lecture_sleep {
    public static void main(String[] args) {
//        Scanner in = new Scanner(new File("lecture_sleep.in"));
        Scanner in = new Scanner(System.in);
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        int[] theorems = new int[n];
        boolean[] awake = new boolean[n];
        int def = 0;
        for (int i=0;i<n;i++) {
            theorems[i] = in.nextInt();
        }
        for (int i=0;i<n;i++) {
            awake[i] = in.nextInt()==1;
            if (awake[i]) def += theorems[i];
        }
        int[] sums = new int[n];
        in.close();
        if (!awake[0]) sums[0] = theorems[0];
        for (int i=1;i<n;i++) {
            sums[i] = sums[i-1] + ((awake[i]) ? 0: theorems[i]);
        }
        int max = sums[k-1];
        for (int i=1;i<n-k+1;i++) {
            int sum = sums[i+k-1]-sums[i-1];
            if (sum>max) {
                max = sum;
            }
        }
        System.out.println(max+def);
    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class lecture_sleep {
    public static void main(String[] args) {
//        Scanner in = new Scanner(new File("lecture_sleep.in"));
        Scanner in = new Scanner(System.in);
        int n,k;
        n = in.nextInt();
        k = in.nextInt();
        int[] theorems = new int[n];
        ArrayList<Integer> zeros = new ArrayList<>();
        boolean[] awake = new boolean[n];
        int def = 0;
        for (int i=0;i<n;i++) {
            theorems[i] = in.nextInt();
        }
        for (int i=0;i<n;i++) {
            awake[i] = in.nextInt()==1;
            if (!awake[i]) zeros.add(i);
            else def += theorems[i];
        }
        int[] sums = new int[n];
        in.close();
        if (!awake[0]) sums[0] = theorems[0];
        for (int i=1;i<n;i++) {
            sums[i] = sums[i-1] + ((awake[i]) ? 0: theorems[i]);
        }
        int max = sums[k-1];
        for (int i=1;i<n-k+1;i++) {
            int sum = sums[i+k-1]-sums[i-1];
            if (sum>max) {
                max = sum;
            }
        }
        System.out.println(max+def);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        int[] t = new int[n];
        int[] prod = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextInt();
        for(int i = 0; i < n; i++) {
            t[i] = in.nextInt();
            if(t[i] == 1)
                prod[i] = 0;
            else
                prod[i] = a[i];
        }
        int sum = 0;
        int index = 0;
        for(int i = 0; i < k; i++)
            sum += prod[i];
        int max = sum;
        for(int i = k; i < n; i++) {
            sum += prod[i]-prod[i-k];
            if(sum > max) {
                max = sum;
                index = i-k+1;
            }
        }
        sum = 0;
        for(int i = 0; i < index; i++) {
            if(t[i] == 1)
                sum += a[i];
        }
        for(int i = index; i < index + k; i++) {
            sum += a[i];
        }
        for(int i = index+k; i < n; i++) {
            if(t[i] == 1)
                sum += a[i];
        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        int[] t = new int[n];
        int[] prod = new int[n];
        for(int i = 0; i < n; i++)
            a[i] = in.nextInt();
        for(int i = 0; i < n; i++) {
            t[i] = in.nextInt();
            if(t[i] == 1)
                prod[i] = 0;
            else
                prod[i] = a[i];
        }
        int sum = 0;
        int index = 0;
        for(int i = 0; i < k; i++)
            sum += prod[i];
        int max = sum;
        for(int i = k; i < n; i++) {
            sum += prod[i]-prod[i-k];
            if(sum > max) {
                max = sum;
                index = i-k+1;
            }
        }
        sum = 0;
        for(int i = 0; i < index+k; i++) {
            sum += a[i];
        }
        for(int i = index+k; i < n; i++) {
            if(t[i] == 1)
                sum += a[i];
        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        int[] t = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for(int i = 0; i < n; i++) {
            t[i] = in.nextInt();
        }

        int sumall = 0;
        int index = 0;

        for(int i = 0; i <= n-k; i++) {
            int theirsum = 0;
            for(int j = i; j < i+k; j++) {
                if(t[j] == 0)
                    theirsum += a[j];
            }
            if(theirsum > sumall) {
                sumall = theirsum;
                index = i;
            }
        }
        int answer = 0;
        for(int i = 0; i < n; i++) {
            if(t[i] == 1)
                answer += a[i];
        }
        System.out.println(answer + sumall);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        int[] t = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for(int i = 0; i < n; i++) {
            t[i] = in.nextInt();
        }

        int max = 0;
        int index = 0;
        for(int i = 0; i <= n-k; i++) {
            int tempsum = 0;
            for(int j = i; j < i+k; j++)
                tempsum += a[j];
            if(tempsum > max) {
                max = tempsum;
                index = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i >= index && i <= index+k-1) {
                continue;
            }
            else if(t[i] == 1)
                max += a[i];
        }
        System.out.println(max);
    }
}


import java.util.*;
import java.io.*;
import java.math.*;

public class b {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        int[] t = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for(int i = 0; i < n; i++) {
            t[i] = in.nextInt();
        }

        int max = 0;
        int index = 0;
        for(int i = 0; i <= n-k; i++) {
            if(t[i] == 1)
                continue;
            int tempsum = 0;
            for(int j = i; j < i+k; j++)
                tempsum += a[j];
            if(tempsum > max) {
                max = tempsum;
                index = i;
            }
        }
        for(int i = 0; i < n; i++){
            if(i >= index && i <= index+k-1) {
                continue;
            }
            else if(t[i] == 1)
                max += a[i];
        }
        System.out.println(max);
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class TaskA implements Runnable {
    long m = (int)1e9+7;
    PrintWriter w;
    InputReader c;
    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);
        int n = c.nextInt();
        int k = c.nextInt();
        int a[] =scanArrayI(n);
        int t[] = scanArrayI(n);

        long total_sum=0;
        for(int i=0;i<n;i++) if(t[i]==1) total_sum+=a[i];
        long temp_sum=0;
        for(int i=0;i<k;i++) if(t[i]==0) temp_sum+=a[i];
        //w.println(temp_sum);
        for(int i=k;i<n;i++){
            long t2 = temp_sum;
            if(t[i-k]==0) t2-=a[i-k];
            if(t[i]==0) t2+=a[i];
            //w.println(t2);
            if(t2>temp_sum) temp_sum = t2;
        }
        total_sum+=temp_sum;
        w.println(total_sum);

        w.close();
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });

    }
    public static class DJSet {
        public int[] upper;

        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }
    public static int[] radixSort(int[] f)    {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        return f;
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new TaskA(),"TaskA",1<<26).start();
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class TaskA implements Runnable {
    long m = (int)1e9+7;
    PrintWriter w;
    InputReader c;
    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);
        int n = c.nextInt();
        int k = c.nextInt();
        int a[] = scanArrayI(n);
        int t[] = scanArrayI(n);

        long total_sum=0;
        for(int i=0;i<n;i++) total_sum += (a[i]*t[i]);
        long temp_sum=0;
        for(int i=0;i<k;i++) if(t[i]==0) temp_sum += a[i];
        long ans=temp_sum;
        //w.println(temp_sum);
        for(int i=k;i<n;i++){
            if(t[i-k]==0) temp_sum -= a[i-k];
            if(t[i]==0) temp_sum += a[i];
            //w.println(t2);
            if(temp_sum>ans) ans = temp_sum;
        }
        total_sum += ans;
        w.println(total_sum);

        w.close();
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });

    }
    public static class DJSet {
        public int[] upper;

        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }
    public static int[] radixSort(int[] f)    {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        return f;
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new TaskA(),"TaskA",1<<26).start();
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class TaskA implements Runnable {
    long m = (int)1e9+7;
    PrintWriter w;
    InputReader c;
    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);
        int n = c.nextInt();
        int k = c.nextInt();
        int a[] = scanArrayI(n);
        int t[] = scanArrayI(n);

        long total_sum=0;
        for(int i=0;i<n;i++) total_sum += (a[i]*t[i]);
        long temp_sum=0,ans=temp_sum;
        for(int i=0;i<k;i++) if(t[i]==0) temp_sum += a[i];
        //w.println(temp_sum);
        for(int i=k;i<n;i++){
            if(t[i-k]==0) temp_sum -= a[i-k];
            if(t[i]==0) temp_sum += a[i];
            //w.println(t2);
            if(temp_sum>ans) ans = temp_sum;
            temp_sum = temp_sum;
        }
        total_sum += ans;
        w.println(total_sum);

        w.close();
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });

    }
    public static class DJSet {
        public int[] upper;

        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }
    public static int[] radixSort(int[] f)    {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        return f;
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new TaskA(),"TaskA",1<<26).start();
    }
}


import java.io.*;
import java.util.*;
import java.lang.*;
import static java.lang.Math.*;

public class TaskA implements Runnable {
    long m = (int)1e9+7;
    PrintWriter w;
    InputReader c;
    public void run() {
        c = new InputReader(System.in);
        w = new PrintWriter(System.out);
        int n = c.nextInt();
        int k = c.nextInt();
        int a[] =scanArrayI(n);
        int t[] = scanArrayI(n);

        long total_sum=0,x=0,y=0;
        for(int i=0;i<n;i++) if(t[i]==1) total_sum+=a[i];
        long temp_sum=0;
        for(int i=0;i<k;i++) if(t[i]==0) temp_sum+=a[i];
        //w.println(temp_sum);
        for(int i=k;i<n;i++){
            long t2 = temp_sum;
            if(t[i-k]==0) t2-=a[i-k];
            if(t[i]==0) t2+=a[i];
            //w.println(t2);
            if(t2>temp_sum) temp_sum = t2;
        }
        w.println(total_sum+temp_sum);

        w.close();
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    public static void sortbyColumn(int arr[][], int col){
        Arrays.sort(arr, new Comparator<int[]>()
        {
            public int compare(int[] o1, int[] o2){
                return(Integer.valueOf(o1[col]).compareTo(o2[col]));
            }
        });

    }
    public static class DJSet {
        public int[] upper;

        public DJSet(int n) {
            upper = new int[n];
            Arrays.fill(upper, -1);
        }

        public int root(int x) {
            return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
        }

        public boolean equiv(int x, int y) {
            return root(x) == root(y);
        }

        public boolean union(int x, int y) {
            x = root(x);
            y = root(y);
            if (x != y) {
                if (upper[y] < upper[x]) {
                    int d = x;
                    x = y;
                    y = d;
                }
                upper[x] += upper[y];
                upper[y] = x;
            }
            return x == y;
        }
    }
    public static int[] radixSort(int[] f)    {
        int[] to = new int[f.length];
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]&0xffff)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]&0xffff]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        {
            int[] b = new int[65537];
            for(int i = 0;i < f.length;i++)b[1+(f[i]>>>16)]++;
            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
            for(int i = 0;i < f.length;i++)to[b[f[i]>>>16]++] = f[i];
            int[] d = f; f = to;to = d;
        }
        return f;
    }
    public void printArray(int[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    public int[] scanArrayI(int n){
        int a[] = new int[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextInt();
        return a;
    }
    public long[] scanArrayL(int n){
        long a[] = new long[n];
        for(int i=0;i<n;i++)
            a[i] = c.nextLong();
        return a;
    }
    public void printArray(long[] a){
        for(int i=0;i<a.length;i++)
            w.print(a[i]+" ");
        w.println();
    }
    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
    public static void main(String args[]) throws Exception {
        new Thread(null, new TaskA(),"TaskA",1<<26).start();
    }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int [] thms = new int[n];
      int [] sleep = new int[n];
      int sum=0;
      for (int i=0;i<n;i++){
         thms[i]= sc.nextInt();
         sum+=thms[i];
      }
      for (int i=0;i<n;i++){
         sleep[i] = sc.nextInt();
      }
      for (int i=0;i<n-k;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,i+k);
      }
      for (int i=n-k;i<n;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,n);
      }
      System.out.println(sum);
   }
   public static int findAmt(int[] a,int[] b, int start, int end){
      int result=0;
      for (int i=start,i<end,i++){
         if(b[i]==0) result+=a[i];

      }
      return result;
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc =new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int [] vals = new int[n];
      int [] times = new int[n];
      for(int i=0;i<n;i++){
         vals[i] = sc.nextInt();
      }
      for(int i=0;i<n;i++){
         times[i] = sc.nextInt();
      }
      int sum = 0;
      for(int i=0;i<n;i++){
         sum+=times[i]*vals[i];
      }
      int [] prefix = new int[n+1];
      for(int i=0;i<n;i++){
         if(times[i]==0){
            prefix[i+1]=prefix[i]+vals[i];
         }
         else{
            prefix[i+1]=prefix[i];
         }
      }
      // for(int i=0;i<n+1;i++){
      //    System.out.println(prefix[i]);
      // }
      int max = 0;
      for(int i=k;i<n+1;i++){
         max = Math.max(max,prefix[i]-prefix[i-k]);
      }
      System.out.println(max+sum);
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int [] thms = new int[n];
      int [] sleep = new int[n];
      int sum=0;
      for (int i=0;i<n;i++){
         thms[i]= sc.nextInt();
         sum+=thms[i];
      }
      for (int i=0;i<n;i++){
         sleep[i] = sc.nextInt();
      }
      for (int i=0;i<n-k;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,i+k);
      }
      for (int i=n-k;i<n;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,n));
      }
      System.out.println(sum);
   }
   public static int findAmt(int[] a,int[] b, int start, int end){
      int result=0;
      for (int i=start,i<end,i++){
         if(b[i]==0) result+=a[i];

      }
      return result;
   }
}


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int k = sc.nextInt();
      int [] thms = new int[n];
      int [] sleep = new int[n];
      int sum=0;
      for (int i=0;i<n;i++){
         thms[i]= sc.nextInt();
         sum+=thms[i];
      }
      for (int i=0;i<n;i++){
         sleep[i] = sc.nextInt();
      }
      for (int i=0;i<n-k;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,i+k));
      }
      for (int i=n-k;i<n;i++){
         sum=Math.max(sum,findAmt(thms,sleep,i,n));
      }
      System.out.println(sum);
   }
   public static int findAmt(int[] a,int[] b, int start, int end){
      int result=0;
      for (int i=start,i<end,i++){
         if(b[i]==0) result+=a[i];

      }
      return result;
   }
}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
                	}

		  }
          if(n!=1)
          System.out.println(sum);
          else
        	  System.out.println(arr[0]);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];
             boolean wtflag=true;

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
                       {   if(weight[i]==0)

			              {sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
	             	      //System.out.println("sum"+i+"="+sum);
			              wtflag=false;
			              }
                       }

	        	          else
	        	          {         if(weight[i]==0)

						              {sum=Math.max((S[n-1]-S[i-1])+sums[n-1]-(sums[n-1]- sums[i-1]), sum);
				            	      //System.out.println("sum"+i+"="+sum);
						              wtflag=false;
						              }
	        	          }
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		                {sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
  		              wtflag=false;
                	    }
          	          else
            	          if(weight[i]==0)

    		                {sum=S[n-1];
                  //	System.out.println("sum"+i+"="+sum);
    		              wtflag=false;
                  	    }

                	}
         }
          if(wtflag==true)
        	System.out.println(S[n-1]);
          else
          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         int sums[]= new int[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         int sum=-1;
         int S[]= new int[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.*;
import java.util.*;
import java.util.*;
import java.util.*;
public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];

        for(int i=1;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();

         int sums[]= new int[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         int sum=-1;
         int S[]= new int[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max(((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1])), sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=sums[i+k-1];
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  //System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
      /*  for(int i=1;i<n;i++)
        System.out.print(weight[i]+" ");
        System.out.println();
        for(int i=0;i<n;i++)
        System.out.print(arr[i]+" ");
        System.out.println();
        */
         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];

             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];
             boolean wtflag=true;
            /* for(int i=0;i<n;i++)
                 System.out.print(S[i]+" ");
             for(int i=0;i<n;i++)
                 System.out.print(sums[i]+" ");
             System.out.println();
             */

         for(int i=0;i<n;i++)
         {     if(i!=0)
		                     {   if((i+k-1) <n)
				                       {   if(weight[i]==0)

									              {sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
							             	      //System.out.println("sum"+i+"="+sum);
									              wtflag=false;
									              }
				                        }

					        	          else
					        	          {         if(weight[i]==0)

										              {sum=Math.max((S[n-1]-S[i-1])+sums[n-1]-(sums[n-1]- sums[i-1]), sum);
								            	     // System.out.println("sum"+i+"="+sum);
										              wtflag=false;
										              }
					        	          }
		                    }
                else
		                	 {  if((i+k-1) <n)
		          	           		if(weight[i]==0)

				  		                {sum=S[i+k-1]+sums[n-1]-sums[i+k-1];
				                	   // System.out.println("sum"+i+"="+sum);
				  		                 wtflag=false;
				                	    }
		          	           else
		            	          if(weight[i]==0)

		    		                {sum=S[n-1];
		                  	       // System.out.println("sum"+i+"="+sum);
		    		                 wtflag=false;
	                  	             }

                	       }
         }
          if(wtflag==true)
        	System.out.println(S[n-1]);
          else
          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         int sums[]= new int[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         int sum=-1;
         int S[]= new int[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];
             boolean wtflag=true;

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              {sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
		              wtflag=false;
		              }
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		                {sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
  		              wtflag=false;
                	    }

                	}
         }
          if(wtflag==true)
        	System.out.println(S[n-1]);
          else
          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
   System.out.println("n="+n);
   System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        for(int i=1;i<n;i++)
        System.out.print(weight[i]+" ");
        System.out.println();
        for(int i=0;i<n;i++)
        System.out.print(arr[i]+" ");
        System.out.println();

         int sums[]= new int[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         int sum=-1;
         int S[]= new int[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                	System.out.println("sum"+i+"="+sum);
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class stt {

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];
  // System.out.println("n="+n);
  // System.out.println("k="+k);
        for(int i=0;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();
        //for(int i=1;i<n;i++)
        //System.out.print(weight[i]+" ");
        //System.out.println();
        //for(int i=0;i<n;i++)
       // System.out.print(arr[i]+" ");
        //System.out.println();

         long sums[]= new long[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         long sum=-1;
         long S[]= new long[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1]), sum);
             	      //System.out.println("sum"+i+"="+sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                //	System.out.println("sum"+i+"="+sum);
                	}

		  }
          if(k!=1)
          System.out.println(sum);
          else
          { Arrays.sort(arr);
          System.out.println(arr[n-1]);
          }

	}

}


import java.io.*;
import java.util.*;
import java.util.*;
import java.util.*;
public class stt {
		public static int str(String s)
		{ return 1+ str(s.substring(1));

		}

	public static void main(String[] args) {
    //int sz = 1 << 15;
 //   Scanner in = new Scanner(new BufferedInputStream(System.in, sz));
 //   PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out, sz));
		Scanner s= new Scanner(System.in);
        int n=s.nextInt();
        int k= s.nextInt();

        int arr[]= new int[n];
        int weight[]= new int[n];

        for(int i=1;i<n;i++)
        	arr[i]=s.nextInt();

        for(int i=0;i<n;i++)
        	weight[i]=s.nextInt();

         int sums[]= new int[n];
         sums[0]=arr[0]*weight[0];
         for(int i=1;i<n;i++)
         	sums[i]=sums[i-1]+(arr[i]*weight[i]);
         int sum=-1;
         int S[]= new int[n];
             S[0]= arr[0];
             for(int i=1;i<n;i++)
              S[i]=S[i-1]+arr[i];

         for(int i=0;i<n;i++)
         {     if(i!=0)
                 {   if((i+k-1) <n)
        	          if(weight[i]==0)

		              sum=Math.max(((S[i+k-1]-S[i-1])+sums[n-1]-(sums[i+k-1]- sums[i-1])), sum);
                 }
                else
                	{if((i+k-1) <n)
          	          if(weight[i]==0)

  		              sum=S[i+k-1];
                	}

		  }

          System.out.println(sum);

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;

public class B {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static String next() throws IOException {
        in.nextToken();
        return (String) in.sval;
    }

    static Node node[] = new Node[100005];
    static int a[] = new int[100005];
    static int n, k;
    public static void main(String[] args) throws IOException {
//        LinkedList<Node> list = new LinkedList<>();
        for(int i = 0; i < 100005; i++){
            node[i] = new Node();
        }
        n = nextInt();
        k = nextInt();
        int sum = 0;
        for(int i = 1; i <= n; i++){
            a[i] = nextInt();
        }
        int tmp;
        int num = 0;
        for(int i = 1; i <= n; i++){
            tmp = nextInt();
            if(tmp == 1){
                sum += a[i];
            }else{
                node[num].time = i;
                node[num++].num = a[i];
            }
        }
//        out.println("sum = " + sum);
        int ans = 0, flag = 0;  // flag  记录尾巴的下标、、
        int maxAns = 0;
        for(int i = 0; i < num; i++){

            if(k > node[i].time - node[flag].time){
                ans += node[i].num;
//                out.println("增加：" + node[i].time + "时间、讲解的定理数量：" + node[i].num);
            }else{
                ans -= node[flag].num;
//                out.println("减少：" + node[flag].time + "时间、讲解的定理数量：" + node[flag].num);
            }
//            out.println("ans = " + ans);
            maxAns = Math.max(ans, maxAns);
        }
        out.println(maxAns + sum);
        out.flush();

    }

    static class Node{
        int time, num; //在 第 time 分钟 讲解的定理数量、、

        public Node() {
        }

        public Node(int time, int num) {
            this.time = time;
            this.num = num;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;

public class B {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static String next() throws IOException {
        in.nextToken();
        return (String) in.sval;
    }

    static Node node[] = new Node[100005];
    static int a[] = new int[100005];
    static int n, k;

    public static void main(String[] args) throws IOException {
//        LinkedList<Node> list = new LinkedList<>();
        for (int i = 0; i < 100005; i++) {
            node[i] = new Node();
        }
        n = nextInt();
        k = nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            a[i] = nextInt();
        }
        int tmp;
        int num = 0;
        for (int i = 1; i <= n; i++) {
            tmp = nextInt();
            if (tmp == 1) {
                sum += a[i];
            } else {
                node[num].time = i;
                node[num++].num = a[i];
            }
        }

        long ans = 0, maxAns = 0;
        int flag = 0;
        if (k > 0) {
            for (int i = 0; i < num; i++) {
                if (k > node[i].time - node[flag].time) {
                    ans += node[i].num;
//                    out.println("增加：" + node[i].time + "时间、讲解的定理数量：" + node[i].num);
                } else {
                    ans -= node[flag].num;
//                    out.println("减少：" + node[flag].time + "时间、讲解的定理数量：" + node[flag].num);
                    flag++;  // 指向尾巴的指针+1，
                    i--;
                }
//                out.println("ans = " + ans);
                maxAns = Math.max(ans, maxAns);
            }
        }

        out.println(maxAns + sum);
        out.flush();

    }

    static class Node {

        int time, num; //在 第 time 分钟 讲解的定理数量、、

        public Node() {
        }

        public Node(int time, int num) {
            this.time = time;
            this.num = num;
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.LinkedList;

public class B {

    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

    public static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }

    public static String next() throws IOException {
        in.nextToken();
        return (String) in.sval;
    }

    static Node node[] = new Node[100005];
    static int a[] = new int[100005];
    static int n, k;
    public static void main(String[] args) throws IOException {
//        LinkedList<Node> list = new LinkedList<>();
        for(int i = 0; i < 100005; i++){
            node[i] = new Node();
        }
        n = nextInt();
        k = nextInt();
        long sum = 0;
        for(int i = 1; i <= n; i++){
            a[i] = nextInt();
        }
        int tmp;
        int num = 0;
        for(int i = 1; i <= n; i++){
            tmp = nextInt();
            if(tmp == 1){
                sum += a[i];
            }else{
                node[num].time = i;
                node[num++].num = a[i];
            }
        }
//        out.println("sum = " + sum);
        long ans = 0, maxAns = 0;
        int flag = 0;
        for(int i = 0; i < num; i++){

            if(k > node[i].time - node[flag].time){
                ans += node[i].num;
//                out.println("增加：" + node[i].time + "时间、讲解的定理数量：" + node[i].num);
            }else{
                ans -= node[flag].num;
//                out.println("减少：" + node[flag].time + "时间、讲解的定理数量：" + node[flag].num);
            }
//            out.println("ans = " + ans);
            maxAns = Math.max(ans, maxAns);
        }
        out.println(maxAns + sum);
        out.flush();

    }

    static class Node{
        int time, num; //在 第 time 分钟 讲解的定理数量、、

        public Node() {
        }

        public Node(int time, int num) {
            this.time = time;
            this.num = num;
        }
    }
}