import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Roy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader reader, OutputWriter writer) {
            int n = reader.readInteger();
            int k = reader.readInteger();

            int a[] = new int[n];
            int cSum[] = new int[n];
            Arrays.fill(cSum, 0);

            int pos = 0;
            long max = Long.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                a[i] = reader.readInteger();

                if (i >= k) {
                    cSum[i] += (a[i] + cSum[i - 1]) - a[i - k];
                } else if (i == 0) {
                    cSum[i] = a[i];
                } else {
                    cSum[i] += a[i - 1];
                }
                if (cSum[i] > max) {
                    pos = i;
                    max = cSum[i];
                }
            }

            int sleep[] = new int[n];
            for (int i = 0; i < n; i++) {
                sleep[i] = reader.readInteger();
            }

            long ans = 0;
            int first = pos - k;
            for (int i = 0; i <= first; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            int second = pos;
            for (int i = first + 1; i <= second; i++) {
                ans += a[i];
            }
            for (int i = second + 1; i < n; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            writer.print(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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 int readInteger() {
            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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Roy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader reader, OutputWriter writer) {
            int n = reader.readInteger();
            int k = reader.readInteger();

            int a[] = new int[n];
            long cSum[] = new long[n];

            int pos = 0;
            long max = Long.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                a[i] = reader.readInteger();

                if (i == 0) {
                    cSum[i] = a[i];
                } else if (i >= k) {
                    cSum[i] = (a[i] + cSum[i - 1]) - a[i - k];
                } else {
                    cSum[i] = cSum[i - 1] + a[i];
                }

                if (cSum[i] > max) {
                    pos = i;
                    max = cSum[i];
                }
            }

            int sleep[] = new int[n];
            for (int i = 0; i < n; i++) {
                sleep[i] = reader.readInteger();
            }

            long ans = 0;
            int first = pos - k;
            for (int i = 0; i <= first; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }

            int second = pos;
            for (int i = first + 1; i <= second; i++) {
                ans += a[i];
            }
            for (int i = second + 1; i < n; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            writer.print(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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 int readInteger() {
            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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Roy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader reader, OutputWriter writer) {
            int n = reader.readInteger();
            int k = reader.readInteger();

            int a[] = new int[n + 1];
            long cSum[] = new long[n + 1];

            cSum[0] = a[0] = 0;

            int pos = 0;
            long max = Long.MIN_VALUE;
            for (int i = 1; i <= n; i++) {
                a[i] = reader.readInteger();

                if (i == 0) {
                    cSum[i] = a[i];
                } else {
                    cSum[i] = cSum[i - 1] + a[i];
                }
            }

            long diff;
            int sleep[] = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                sleep[i] = reader.readInteger();
                if (sleep[i] == 0 && i >= k) {
                    diff = cSum[i] - cSum[i - k];
                    if (diff > max) {
                        pos = i;
                        max = diff;
                    }
                }
            }

            long ans = 0;
            int first = n;
            if (pos != 0) {
                first = pos - k;
            }

            for (int i = 1; i <= first; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }

            int second = first;
            if (pos != 0) {
                second = pos;
            }
            for (int i = first + 1; i <= second; i++) {
                ans += a[i];
            }
            for (int i = second + 1; i < n; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            writer.print(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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 int readInteger() {
            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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Roy
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader reader, OutputWriter writer) {
            int n = reader.readInteger();
            int k = reader.readInteger();

            int a[] = new int[n];
            int cSum[] = new int[n];
//        Arrays.fill(cSum, 0);

            int pos = 0;
            long max = Long.MIN_VALUE;
            for (int i = 0; i < n; i++) {
                a[i] = reader.readInteger();

                if (i == 0) {
                    cSum[i] = a[i];
                } else if (i >= k) {
                    cSum[i] = (a[i] + cSum[i - 1]) - a[i - k];
                } else {
                    cSum[i] = cSum[i - 1] + a[i];
                }

                if (cSum[i] > max) {
                    pos = i;
                    max = cSum[i];
                }
            }

            int sleep[] = new int[n];
            for (int i = 0; i < n; i++) {
                sleep[i] = reader.readInteger();
            }

            long ans = 0;
            int first = pos - k;
            for (int i = 0; i <= first; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            int second = pos;
            for (int i = first + 1; i <= second; i++) {
                ans += a[i];
            }
            for (int i = second + 1; i < n; i++) {
                if (sleep[i] != 0) {
                    ans += a[i];
                }
            }
            writer.print(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void close() {
            writer.flush();
            writer.close();
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.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 int readInteger() {
            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 boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    public class Obj implements Comparable<Obj>{
        public int start;
        public int end;

        public Obj(int start_, int end_){
            this.start = start_;
            this.end = end_;

        }

        public int compareTo(Obj other){
            if (other.start == this.start){
                return this.end - other.end;
            }
            return this.start - other.start;
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Codechef cf = new Codechef();
        cf.Solve();
	}

	public void Solve(){
        MyScanner sc = new MyScanner();
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[k];
        int[] max = new int[k];
        int[] sum = new int[k];
        int[] zrr = new int[k];
        int[] sumrev = new int[k];
        for (int i = 0; i < k; ++i){
            arr[i] = sc.nextInt();
            max[i] = arr[i];
            if (i > 0) max[i] += max[i-1];
            // System.out.print(max[i] + " ");
        }
        for (int i = 0; i < k; ++i){
            zrr[i] = sc.nextInt();
            if (zrr[i] == 1) sum[i] = arr[i];
            if (i > 0) sum[i] += sum[i-1];
        }

        for (int i = k - 1; i >= 0; --i){
            if (zrr[i] == 1) sumrev[i] = arr[i];
            if (i < k - 1) sumrev[i] += sumrev[i+1];
        }

        int res = 0;
        for (int i = 0; i < k; ++i){
            int best = Math.max(i - n + 1, 0);
            int nosleep = max[i];
            if (best > 0){
                nosleep -= max[best-1];
                nosleep += sum[best-1];
            }
            if (i < n-1) nosleep += sumrev[i+1];
            res = Math.max(res, nosleep);
        }
        System.out.println(res);
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
    public class Obj implements Comparable<Obj>{
        public int start;
        public int end;

        public Obj(int start_, int end_){
            this.start = start_;
            this.end = end_;

        }

        public int compareTo(Obj other){
            if (other.start == this.start){
                return this.end - other.end;
            }
            return this.start - other.start;
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Codechef cf = new Codechef();
        cf.Solve();
	}

	public void Solve(){
        MyScanner sc = new MyScanner();
        int k = sc.nextInt();
        int n = sc.nextInt();
        int[] arr = new int[k];
        int[] max = new int[k];
        int[] sum = new int[k];
        int[] zrr = new int[k];
        int[] sumrev = new int[k];
        for (int i = 0; i < k; ++i){
            arr[i] = sc.nextInt();
            max[i] = arr[i];
            if (i > 0) max[i] += max[i-1];
            // System.out.print(max[i] + " ");
        }
        for (int i = 0; i < k; ++i){
            zrr[i] = sc.nextInt();
            if (zrr[i] == 1) sum[i] = arr[i];
            if (i > 0) sum[i] += sum[i-1];
        }

        for (int i = k - 1; i >= 0; --i){
            if (zrr[i] == 1) sumrev[i] = arr[i];
            if (i < k - 1) sumrev[i] += sumrev[i+1];
        }

        int res = 0;
        for (int i = 0; i < k; ++i){
            int best = Math.max(i - n + 1, 0);
            int nosleep = max[i];
            if (best > 0){
                nosleep -= max[best-1];
                nosleep += sum[best-1];
                if (i < n-1) nosleep += sumrev[i+1];
            }
            res = Math.max(res, nosleep);
        }
        System.out.println(res);
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public class Obj implements Comparable<Obj>{
        public int start;
        public int end;

        public Obj(int start_, int end_){
            this.start = start_;
            this.end = end_;

        }

        public int compareTo(Obj other){
            if (other.start == this.start){
                return this.end - other.end;
            }
            return this.start - other.start;
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Codechef cf = new Codechef();
        cf.Solve();
	}

	public void Solve(){
        MyScanner sc = new MyScanner();
        int k = sc.nextInt();
        int n = sc.nextInt();
        long[] arr = new long[k];
        long[] max = new long[k];
        long[] sum = new long[k];
        long[] zrr = new long[k];
        long[] sumrev = new long[k];
        for (int i = 0; i < k; ++i){
            arr[i] = sc.nextInt();
            max[i] = arr[i];
            if (i > 0) max[i] += max[i-1];
            // System.out.print(max[i] + " ");
        }
        for (int i = 0; i < k; ++i){
            zrr[i] = sc.nextInt();
            if (zrr[i] == 1) sum[i] = arr[i];
            if (i > 0) sum[i] += sum[i-1];
        }

        for (int i = k - 1; i >= 0; --i){
            if (zrr[i] == 1) sumrev[i] = arr[i];
            if (i < k - 1) sumrev[i] += sumrev[i+1];
        }

        long res = 0L;
        for (int i = n-1; i < k; ++i){
            int best = Math.max(i - n + 1, 0);
            long nosleep = max[i];
            if (best > 0){
                nosleep -= max[best-1];
                nosleep += sum[best-1];
            }
            if (i < n-1) nosleep += sumrev[i+1];
            res = Math.max(res, nosleep);
        }
        System.out.println(res);
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public class Obj implements Comparable<Obj>{
        public int start;
        public int end;

        public Obj(int start_, int end_){
            this.start = start_;
            this.end = end_;

        }

        public int compareTo(Obj other){
            if (other.start == this.start){
                return this.end - other.end;
            }
            return this.start - other.start;
        }

    }

	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
        Codechef cf = new Codechef();
        cf.Solve();
	}

	public void Solve(){
        MyScanner sc = new MyScanner();
        int k = sc.nextInt();
        int n = sc.nextInt();
        long[] arr = new long[k];
        long[] max = new long[k];
        long[] sum = new long[k];
        long[] zrr = new long[k];
        long[] sumrev = new long[k];
        for (int i = 0; i < k; ++i){
            arr[i] = sc.nextInt();
            max[i] = arr[i];
            if (i > 0) max[i] += max[i-1];
            // System.out.print(max[i] + " ");
        }
        for (int i = 0; i < k; ++i){
            zrr[i] = sc.nextInt();
            if (zrr[i] == 1) sum[i] = arr[i];
            if (i > 0) sum[i] += sum[i-1];
        }

        for (int i = k - 1; i >= 0; --i){
            if (zrr[i] == 1) sumrev[i] = arr[i];
            if (i < k - 1) sumrev[i] += sumrev[i+1];
        }

        long res = 0L;
        for (int i = n-1; i < k; ++i){
            int best = Math.max(i - n + 1, 0);
            long nosleep = max[i];
            if (best > 0){
                nosleep -= max[best-1];
                nosleep += sum[best-1];
            }
            if (i < k-1) nosleep += sumrev[i+1];
            res = Math.max(res, nosleep);
        }
        System.out.println(res);
	}

	//-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
      try {
         str = br.readLine();
      } catch (IOException e) {
         e.printStackTrace();
      }
      return str;
      }

   }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class EC_41 {

    public static void main(String[] args) throws IOException {
        BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer s = new StringTokenizer(b.readLine());
        int n = Integer.parseInt(s.nextToken());
        int k = Integer.parseInt(s.nextToken());
        int[] A=new int[n+1];
        int[] B=new int[n+1];
        StringTokenizer st = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            A[i]=Integer.parseInt(st.nextToken());
        }
        long sum=0;
        StringTokenizer sc = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            B[i]=Integer.parseInt(sc.nextToken());
            if(B[i]==1){
                sum+=A[i];
            }
        }
        if(n<=k){
            for(int i=1;i<=n;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
        }else{
            for(int i=1;i<=k;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
            long new_sum=sum;
            for(int i=k+1;i<=n;i++){
                if(B[i]==0){
                    new_sum+=A[i];
                    if(B[i-k]==0){
                        new_sum-=A[i-k];
                    }
                }else{
                    if(B[i-k]==0){
                        new_sum-=A[i-k];
                    }
                }
                sum=Math.max(new_sum, sum);
            }

        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class EC_41 {

    public static void main(String[] args) throws IOException {
        BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer s = new StringTokenizer(b.readLine());
        int n = Integer.parseInt(s.nextToken());
        int k = Integer.parseInt(s.nextToken());
        int[] A=new int[n+1];
        int[] B=new int[n+1];
        StringTokenizer st = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            A[i]=Integer.parseInt(st.nextToken());
        }
        long sum=0;
        StringTokenizer sc = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            B[i]=Integer.parseInt(sc.nextToken());
            if(B[i]==1){
                sum+=A[i];
            }
        }
        if(n<=k){
            for(int i=1;i<=n;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
        }else{
            for(int i=1;i<=k;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
            long new_sum=sum;
            for(int i=k+1;i<=n;i++){
                if(B[i]==0){
                    new_sum+=A[i];
                    if(B[i-k]==0){
                        new_sum-=A[i-k];
                    }
                }
                sum=Math.max(new_sum, sum);
            }

        }
        System.out.println(sum);
    }
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class EC_41 {

    public static void main(String[] args) throws IOException {
        BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer s = new StringTokenizer(b.readLine());
        int n = Integer.parseInt(s.nextToken());
        int k = Integer.parseInt(s.nextToken());
        int[] A=new int[n+1];
        int[] B=new int[n+1];
        StringTokenizer st = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            A[i]=Integer.parseInt(st.nextToken());
        }
        long sum=0;
        StringTokenizer sc = new StringTokenizer(b.readLine());
        for(int i=1;i<=n;i++){
            B[i]=Integer.parseInt(sc.nextToken());
            if(B[i]==1){
                sum+=A[i];
            }
        }
        if(n<=k){
            for(int i=1;i<=n;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
        }else{
            for(int i=1;i<=k;i++){
                if(B[i]==0){
                    sum+=A[i];
                }
            }
            long new_sum=sum;
            for(int i=k+1;i<=n;i++){
                if(B[i]==0){
                    new_sum+=A[i];
                    if(B[i-k]==0){
                        new_sum-=A[i];
                    }
                }
                sum=Math.max(new_sum, sum);
            }

        }
        System.out.println(sum);
    }
}


/*
USER: caoash3
LANG: JAVA
TASK:
*/

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

public class lectureSleep {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

		//BufferedReader br = new BufferedReader(new FileReader("X.in"));
		//PrintWriter pw = new PrintWriter(new FileWriter("X.out"));

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(BufferedReader br, PrintWriter pw) throws IOException {
			StringTokenizer st = new StringTokenizer(br.readLine());

			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());

			int[] inp = new int[n];
			int[] sleep = new int[n];

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				inp[i] = Integer.parseInt(st.nextToken());
			}

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				sleep[i] = Integer.parseInt(st.nextToken());
			}

			int[] prefix = new int[n+1];

			prefix[0] = 0;

			for(int i = 1; i <= n; i++) {
				prefix[i] = prefix[i-1] + inp[i-1];
			}

			int[][] dp = new int[n+1][2];

			dp[0][0] = 0;

			//run two passes
			for(int i = 1; i <= n; i++) {
				dp[i][0] = dp[i-1][0] + ((sleep[i-1] == 1) ? inp[i-1] : 0);
			}

			//pass two
			dp[0][1] = 0;

			for(int i = 1; i <= n; i++) {
				dp[i][1] = Math.max(dp[i-1][1] + ((sleep[i-1] == 1) ? inp[i-1] : 0), dp[Math.max(i-k-1, 0)][0] + (prefix[i] - prefix[Math.max(i-k-1, 0)]));
			}

//			for(int i = 0; i < n; i++) {
//				pw.print(prefix[i] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i < n; i++) {
//				pw.print(dp[i][0] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i < n; i++) {
//				pw.print(dp[i][1] + " ");
//			}

			pw.println(Math.max(dp[n-1][0], dp[n-1][1]));

			pw.close();
		}
	}
}


/*
USER: caoash3
LANG: JAVA
TASK:
*/

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

public class lectureSleep {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

		//BufferedReader br = new BufferedReader(new FileReader("X.in"));
		//PrintWriter pw = new PrintWriter(new FileWriter("X.out"));

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(BufferedReader br, PrintWriter pw) throws IOException {
			StringTokenizer st = new StringTokenizer(br.readLine());

			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());

			int[] inp = new int[n];
			int[] sleep = new int[n];

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				inp[i] = Integer.parseInt(st.nextToken());
			}

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				sleep[i] = Integer.parseInt(st.nextToken());
			}

			int[] prefix = new int[n+1];

			prefix[0] = 0;

			for(int i = 1; i <= n; i++) {
				prefix[i] = prefix[i-1] + inp[i-1];
			}

			int[][] dp = new int[n+1][2];

			dp[0][0] = 0;

			//run two passes
			for(int i = 1; i <= n; i++) {
				dp[i][0] = dp[i-1][0] + ((sleep[i-1] == 1) ? inp[i-1] : 0);
			}

			//pass two
			dp[0][1] = 0;

			for(int i = 1; i <= n; i++) {
				dp[i][1] = Math.max(dp[i-1][1] + ((sleep[i-1] == 1) ? inp[i-1] : 0), dp[Math.max(i-k-1, 0)][0] + (prefix[i] - prefix[Math.max(i-k-1, 0)]));
			}

			for(int i = 0; i < n; i++) {
				pw.print(prefix[i] + " ");
			}

			pw.println();
			for(int i = 0; i < n; i++) {
				pw.print(dp[i][0] + " ");
			}

			pw.println();
			for(int i = 0; i < n; i++) {
				pw.print(dp[i][1] + " ");
			}

			pw.println(Math.max(dp[n][0], dp[n][1]));

			pw.close();
		}
	}
}


/*
USER: caoash3
LANG: JAVA
TASK:
*/

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

public class lectureSleep {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

		//BufferedReader br = new BufferedReader(new FileReader("X.in"));
		//PrintWriter pw = new PrintWriter(new FileWriter("X.out"));

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(BufferedReader br, PrintWriter pw) throws IOException {
			StringTokenizer st = new StringTokenizer(br.readLine());

			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());

			int[] inp = new int[n];
			int[] sleep = new int[n];

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				inp[i] = Integer.parseInt(st.nextToken());
			}

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				sleep[i] = Integer.parseInt(st.nextToken());
			}

			int[] prefix = new int[n+1];

			prefix[0] = 0;

			for(int i = 1; i <= n; i++) {
				prefix[i] = prefix[i-1] + inp[i-1];
			}

			int[][] dp = new int[n+1][2];

			dp[0][0] = 0;

			//run two passes
			for(int i = 1; i <= n; i++) {
				dp[i][0] = dp[i-1][0] + ((sleep[i-1] == 1) ? inp[i-1] : 0);
			}

			//pass two
			dp[0][1] = 0;

			for(int i = 1; i <= n; i++) {
				dp[i][1] = Math.max(dp[i-1][1] + ((sleep[i-1] == 1) ? inp[i-1] : 0), dp[Math.max(i-k, 0)][0] + (prefix[i] - prefix[Math.max(i-k, 0)]));
			}

//			for(int i = 0; i <= n; i++) {
//				pw.print(prefix[i] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i <= n; i++) {
//				pw.print(dp[i][0] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i <= n; i++) {
//				pw.print(dp[i][1] + " ");
//			}

			pw.println(Math.max(dp[n][0], dp[n][1]));

			pw.close();
		}
	}
}


/*
USER: caoash3
LANG: JAVA
TASK:
*/

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

public class lectureSleep {
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));

		//BufferedReader br = new BufferedReader(new FileReader("X.in"));
		//PrintWriter pw = new PrintWriter(new FileWriter("X.out"));

		X solver = new X();
		solver.solve(br, pw);
	}

	static class X {
		public void solve(BufferedReader br, PrintWriter pw) throws IOException {
			StringTokenizer st = new StringTokenizer(br.readLine());

			int n = Integer.parseInt(st.nextToken());
			int k = Integer.parseInt(st.nextToken());

			int[] inp = new int[n];
			int[] sleep = new int[n];

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				inp[i] = Integer.parseInt(st.nextToken());
			}

			st = new StringTokenizer(br.readLine());

			for(int i = 0; i < n; i++) {
				sleep[i] = Integer.parseInt(st.nextToken());
			}

			int[] prefix = new int[n+1];

			prefix[0] = 0;

			for(int i = 1; i <= n; i++) {
				prefix[i] = prefix[i-1] + inp[i-1];
			}

			int[][] dp = new int[n+1][2];

			dp[0][0] = 0;

			//run two passes
			for(int i = 1; i <= n; i++) {
				dp[i][0] = dp[i-1][0] + ((sleep[i-1] == 1) ? inp[i-1] : 0);
			}

			//pass two
			dp[0][1] = 0;

			for(int i = 1; i <= n; i++) {
				dp[i][1] = Math.max(dp[i-1][1] + ((sleep[i-1] == 1) ? inp[i-1] : 0), dp[Math.max(i-k-1, 0)][0] + (prefix[i] - prefix[Math.max(i-k-1, 0)]));
			}

//			for(int i = 0; i < n; i++) {
//				pw.print(prefix[i] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i < n; i++) {
//				pw.print(dp[i][0] + " ");
//			}
//
//			pw.println();
//			for(int i = 0; i < n; i++) {
//				pw.print(dp[i][1] + " ");
//			}

			pw.println(Math.max(dp[n][0], dp[n][1]));

			pw.close();
		}
	}
}


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

	public class Solution {
		public static void main(String[] args) {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			InputReader in = new InputReader(inputStream);
			PrintWriter out = new PrintWriter(outputStream);
			Problem solver = new Problem();
			solver.solve(in, out,1);

			out.close();
		}

		// Problem Solver
		static class Problem {
			public void solve(InputReader in, PrintWriter out,int testCase) {
				int n = in.nextInt();
				int k = in.nextInt();
				int[] lectures = new int[n];
				boolean[] awake = new boolean[n];
				for(int i=0;i<n;i++){
					lectures[i]=in.nextInt();
				}
				int awakesum =0;
				for(int i=0;i<n;i++){
					awake[i]=in.nextInt()==1 ? true : false;
					if(awake[i]) awakesum = awakesum+lectures[i];
				}
				int maxsum=0;
				int realmax = 0;
				for(int i=0;i<k;i++){
					if(!awake[i]) maxsum = maxsum+lectures[i];
				}
				realmax = maxsum;
				for(int i = k; i < n;i++){
					if(!awake[i]) maxsum = maxsum + lectures[i];
					if(!awake[i-k]) maxsum = maxsum - lectures[i-k];
					realmax = maxsum > realmax ? maxsum : realmax;
				}
				System.out.println(realmax+awakesum);
			}

		}
		// Insert any additional methods/classes below below
		// Do not touch
		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 500000);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
	}


	package codeforces;

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

	public class Solution {
		public static void main(String[] args) {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			InputReader in = new InputReader(inputStream);
			PrintWriter out = new PrintWriter(outputStream);
			Problem solver = new Problem();
			solver.solve(in, out,1);

			out.close();
		}

		// Problem Solver
		static class Problem {
			public void solve(InputReader in, PrintWriter out,int testCase) {
				int n = in.nextInt();
				int k = in.nextInt();
				int[] lectures = new int[n];
				boolean[] awake = new boolean[n];
				for(int i=0;i<n;i++){
					lectures[i]=in.nextInt();
				}
				int awakesum =0;
				for(int i=0;i<n;i++){
					awake[i]=in.nextInt()==1 ? true : false;
					if(awake[i]) awakesum = awakesum+lectures[i];
				}
				int maxsum=0;
				for(int i=0;i<=n-k;i++){
					int tempmax =0;
					for(int j = i;j<i+k;j++){
						if(!awake[j]) tempmax=tempmax+lectures[j];
					}
					maxsum = tempmax>maxsum ? tempmax : maxsum;
				}
				System.out.println(maxsum+awakesum);
			}

		}
		// Insert any additional methods/classes below below
		// Do not touch
		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 500000);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
	}


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

	public class Solution {
		public static void main(String[] args) {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			InputReader in = new InputReader(inputStream);
			PrintWriter out = new PrintWriter(outputStream);
			Problem solver = new Problem();
			solver.solve(in, out,1);

			out.close();
		}

		// Problem Solver
		static class Problem {
			public void solve(InputReader in, PrintWriter out,int testCase) {
				int n = in.nextInt();
				int k = in.nextInt();
				int[] lectures = new int[n];
				boolean[] awake = new boolean[n];
				for(int i=0;i<n;i++){
					lectures[i]=in.nextInt();
				}
				int awakesum =0;
				for(int i=0;i<n;i++){
					awake[i]=in.nextInt()==1 ? true : false;
					if(awake[i]) awakesum = awakesum+lectures[i];
				}
				int maxsum=0;
				for(int i=0;i<=n-k;i++){
					int tempmax =0;
					for(int j = i;j<i+k;j++){
						if(!awake[j]) tempmax=tempmax+lectures[j];
					}
					maxsum = tempmax>maxsum ? tempmax : maxsum;
				}
				System.out.println(maxsum+awakesum);
			}

		}
		// Insert any additional methods/classes below below
		// Do not touch
		static class InputReader {
			public BufferedReader reader;
			public StringTokenizer tokenizer;

			public InputReader(InputStream stream) {
				reader = new BufferedReader(new InputStreamReader(stream), 500000);
				tokenizer = null;
			}

			public String next() {
				while (tokenizer == null || !tokenizer.hasMoreTokens()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					} catch (IOException e) {
						throw new RuntimeException(e);
					}
				}
				return tokenizer.nextToken();
			}

			public int nextInt() {
				return Integer.parseInt(next());
			}

		}
	}


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

    public class Main {

    public static void main(String[] args) throws IOException{
        //FastScanner in = new FastScanner(new FileInputStream(new File("phi.in")));
        //PrintWriter out = new PrintWriter(new File("output.txt"));
        PrintWriter out = new PrintWriter(System.out);
        FastScanner in = new FastScanner(System.in);
        new Main().solve(in, out);
        out.close();
        System.exit(0);
    }

    /* begin() */

    void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int k = in.nextInt();
        long a[] = new long[n];
        for(int i=0; i<n; i++) a[i] = in.nextInt();
        int b[] = new int[n];
        int j = 0;
        long ans = 0, tmp = 0, max = 0;
        for(int i=0; i<n; i++){
            b[i] = in.nextInt();
            if(b[i] == 1) {ans+= a[i]; if(j<=k) j++; else if(b[i-j+1] == 0) tmp -= a[i-j+1];}
            else{
                tmp += a[i];
                //out.println(tmp);
                if(j<k) j++;
                else if(b[i-j+1] == 0) tmp -= a[i-j+1];
                max = Long.max(max, tmp);
                //out.println(max+" "+j);
            }
        }
        ans+= max;
        out.println(ans);
    }

    /* end() */

    private static class FastScanner {

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

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

        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++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            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 String nextLine() {
            int c = read();
            while (isEndline(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}


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

    public class Main {

    public static void main(String[] args) throws IOException{
        //FastScanner in = new FastScanner(new FileInputStream(new File("phi.in")));
        //PrintWriter out = new PrintWriter(new File("output.txt"));
        PrintWriter out = new PrintWriter(System.out);
        FastScanner in = new FastScanner(System.in);
        new Main().solve(in, out);
        out.close();
        System.exit(0);
    }

    /* begin() */

    void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int k = in.nextInt();
        long a[] = new long[n];
        for(int i=0; i<n; i++) a[i] = in.nextInt();
        long dp[] = new long[n+1];
        int b[] = new int[n+1];
        long ans = 0;
        for(int i=1; i<=n; i++){
            if(in.nextInt() == 0){
                b[i] = b[i-1]+1;
                dp[i] = a[i-1] + dp[i-1];
            } else {
                ans += a[i-1];
                b[i] = b[i-1];
                dp[i] = dp[i-1];
            }
        }
        long max = 0;
        for(int i=k; i<=n; i++){
            max = Long.max(max, dp[i] - dp[i-k]);
        }
        ans+= max;
        out.println(ans);
    }

    /* end() */

    private static class FastScanner {

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

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

        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++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            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 String nextLine() {
            int c = read();
            while (isEndline(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}


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

    public class Main {

    public static void main(String[] args) throws IOException{
        //FastScanner in = new FastScanner(new FileInputStream(new File("phi.in")));
        //PrintWriter out = new PrintWriter(new File("output.txt"));
        PrintWriter out = new PrintWriter(System.out);
        FastScanner in = new FastScanner(System.in);
        new Main().solve(in, out);
        out.close();
        System.exit(0);
    }

    /* begin() */

    void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int k = in.nextInt();
        long a[] = new long[n];
        for(int i=0; i<n; i++) a[i] = in.nextInt();
        int b[] = new int[n];
        int j = 0;
        long ans = 0, tmp = 0, max = 0;
        for(int i=0; i<n; i++){
            b[i] = in.nextInt();
            if(b[i] == 1) {ans+= a[i]; if(j<=k) j++; else if(b[i-j+1] == 0) tmp -= a[i-j+1];}
            else{
                tmp += a[i];
                //out.println(tmp);
                if(j<=k) j++;
                else if(b[i-j+1] == 0) tmp -= a[i-j+1];
                max = Long.max(max, tmp);
            }
        }
        ans+= max;
        out.println(ans);
    }

    /* end() */

    private static class FastScanner {

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

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

        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++];
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public String next() {
            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 String nextLine() {
            int c = read();
            while (isEndline(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}


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

public class B_961 implements Runnable{

    public void solve(){
        int n = scan.nextInt();
        // n++;
        int k = scan.nextInt();
        int ar[] = new int[n+1];
        int preSum[]= new int[n+1];
        int sum[] = new int[n+1];
        int t[] = new int[n+1];
        int pre[] = new int[n+1];
        for(int i=1;i<=n;i++){
            ar[i]=  scan.nextInt();
            preSum[i] = preSum[i-1]+ar[i];
        }
        for(int i=1;i<=n;i++){
            t[i] = scan.nextInt();
        }
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            sum[i] = preSum[i+k-1] - preSum[i-1];
            else
            sum[i] = 0;
        }
        for(int i=1;i<=n;i++){
            if(t[i]==1){
                pre[i] = pre[i-1]+ar[i];
            }else{
                pre[i] = pre[i-1];
            }
        }
        int max = 0;
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            max = Math.max(max,pre[i-1]+sum[i]-pre[i+k-1]+pre[n]);
            else
            max = Math.max(max,pre[i-1]+sum[i]);
        }
        out.println(Arrays.toString(preSum));
        out.println(max);
    }

    InputReader scan;
    PrintWriter out;

    @Override
    public void run(){
        scan = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
    }

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

    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 long[] nla(int n){ //nextLongArray()
            long ar[] = new long[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextLong();
            }
            return ar;
        }

        public int[] nia(int n){
            int ar[] = new int[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextInt();
            }
            return ar;
        }

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

}


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

public class B_961 implements Runnable{

    public void solve(){
        int n = scan.nextInt();
        // n++;
        int k = scan.nextInt();
        int ar[] = new int[n+1];
        int preSum[]= new int[n+1];
        int sum[] = new int[n+1];
        int t[] = new int[n+1];
        int pre[] = new int[n+1];
        for(int i=1;i<=n;i++){
            ar[i]=  scan.nextInt();
            preSum[i] = preSum[i-1]+ar[i];
        }
        for(int i=1;i<=n;i++){
            t[i] = scan.nextInt();
        }
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            sum[i] = preSum[i+k-1] - preSum[i-1];
            else
            sum[i] = 0;
        }
        for(int i=1;i<=n;i++){
            if(t[i]==1){
                pre[i] = pre[i-1]+ar[i];
            }else{
                pre[i] = pre[i-1];
            }
        }
        int max = 0;
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            max = Math.max(max,pre[i-1]+sum[i]-pre[i+k-1]+pre[n]);
            else
            max = Math.max(max,pre[i-1]+sum[i]);
        }
        // out.println(Arrays.toString(preSum));
        out.println(max);
    }

    InputReader scan;
    PrintWriter out;

    @Override
    public void run(){
        scan = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
    }

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

    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 long[] nla(int n){ //nextLongArray()
            long ar[] = new long[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextLong();
            }
            return ar;
        }

        public int[] nia(int n){
            int ar[] = new int[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextInt();
            }
            return ar;
        }

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

}


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

public class B_961 implements Runnable{

    public void solve(){
        int n = scan.nextInt();
        // n++;
        int k = scan.nextInt();
        int ar[] = new int[n+1];
        int preSum[]= new int[n+1];
        int sum[] = new int[n+1];
        int t[] = new int[n+1];
        int pre[] = new int[n+1];
        for(int i=1;i<=n;i++){
            ar[i]=  scan.nextInt();
            preSum[i] = preSum[i-1]+ar[i];
        }
        for(int i=1;i<=n;i++){
            t[i] = scan.nextInt();
        }
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            sum[i] = preSum[i+k-1] - preSum[i-1];
            else
            sum[i] = 0;
        }
        for(int i=1;i<=n;i++){
            if(t[i]==1){
                pre[i] = pre[i-1]+ar[i];
            }else{
                pre[i] = pre[i-1];
            }
        }
        int max = 0;
        for(int i=1;i<=n;i++){
            if(i+k-1<=n)
            max = Math.max(max,pre[i-1]+sum[i]-pre[i+k-1]+pre[n-1]);
            else
            max = Math.max(max,pre[i-1]+sum[i]);
        }
        out.println(max);
    }

    InputReader scan;
    PrintWriter out;

    @Override
    public void run(){
        scan = new InputReader(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.flush();
        out.close();
    }

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

    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 long[] nla(int n){ //nextLongArray()
            long ar[] = new long[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextLong();
            }
            return ar;
        }

        public int[] nia(int n){
            int ar[] = new int[n];
            for(int i=0;i<n;i++){
                ar[i] = this.nextInt();
            }
            return ar;
        }

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

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
        System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));

    }
    static int[] maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        for (int i = 0; i <= array.length-boostLength ; i++) {
            for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            }
            if (max<temp) {
                max=temp;
                res=i;
                temp = 0;
            }
            else {temp=0;}
        }
        for (int i = res; i <res+boostLength ; i++) {
            array[i]=1;
        }
        return array;
    }

    static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        if (boostLength>=array.length) {
            for (int i = 0; i < array.length; i++) {
                res+=values[i];

            }
            return res;
        }
        else {
            for (int i = 0; i < boostLength; i++) {
                temp-=(values[i]*(array[i]-1));
            }
            for (int i = 0; i < array.length; i++) {
                res+=values[i]*array[i];
            }
            for (int i = boostLength; i < array.length ; i++) {
                temp-=(values[i]*(array[i]-1));
                temp+=(values[i-boostLength]*(array[i-boostLength]-1));
                if (max<temp) {
                    max=temp;
              }
            }
            return res+max;}
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        for (int i = 0; i <= array.length-boostLength ; i++) {
            if (array[i]==1) {res+=values[i];}
            for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            }
            if (max<temp) {
                max=temp;
                temp = 0;
            }
            else {temp=0;}
        }
        for (int i = array.length-boostLength+1; i < array.length; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res+max;
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
     //   int res=0;
        int max = 0;
        for (int i = 0; i <= array.length-boostLength ; i++) {
            for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            }
            if (max<temp) {
                max=temp;
               // res=i;
                temp = 0;
            }
            else {temp=0;}
        }
        int sum=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {sum+=values[i];}
        }
        return sum+max;
       /* for (int i = res; i <res+boostLength ; i++) {
            array[i]=1;
        }
        return array;*/
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        if (boostLength==array.length) {
            for (int i = 0; i < boostLength; i++) {
                res+=values[i];

            }
            return res;
        }
        else {
        for (int i = 0; i < boostLength; i++) {
            res+=values[i]*array[i];
            temp-=(values[i]*(array[i]-1));
        }
        for (int i = boostLength; i < array.length ; i++) {
            res+=values[i]*array[i];
           /* for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            } */
            temp-=(values[i]*(array[i]-1));
            temp+=(values[i-boostLength]*(array[i-boostLength]-1));
            if (max<temp) {
                max=temp;
            }
        }
        return res+max;}
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }

    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        if (boostLength>=array.length) {
            for (int i = 0; i < array.length; i++) {
                res+=values[i];

            }
            return res;
        }
        else {
            for (int i = 0; i < boostLength; i++) {
                temp-=(values[i]*(array[i]-1));
            }
            max=temp;
            for (int i = 0; i < array.length; i++) {
                res+=values[i]*array[i];
            }
            for (int i = boostLength; i < array.length ; i++) {
                temp-=(values[i]*(array[i]-1));
                temp+=(values[i-boostLength]*(array[i-boostLength]-1));
                if (max<temp) {
                    max=temp;
              }
            }
            return res+max;}
    }

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        if (boostLength==array.length) {
            for (int i = 0; i < boostLength; i++) {
                res+=values[i];

            }
            return res;
        }
        else {
            for (int i = 0; i < boostLength; i++) {
            // res+=values[i]*array[i];
            temp-=(values[i]*(array[i]-1));
            }
            for (int i = 0; i < array.length; i++) {
                res+=values[i]*array[i];
            }
            for (int i = boostLength; i < array.length ; i++) {
                //res+=values[i]*array[i];
            /* for (int j = 0; j < boostLength; j++) {
                 temp-=(values[i+j]*(array[i+j]-1));
             } */
                temp-=(values[i]*(array[i]-1));
                temp+=(values[i-boostLength]*(array[i-boostLength]-1));
                if (max<temp) {
                    max=temp;
              }
            }
            return res+max;}
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        for (int i = 0; i <= array.length-boostLength ; i++) {
            if (array[i]==1) {res+=values[i];}
            for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            }
            if (max<temp) {
                max=temp;
               // res=i;
                temp = 0;
            }
            else {temp=0;}
        }
        return res+max;
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
        System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));

    }
    static int[] maxEffect (int[] array, int[] values, int boostLength) { //Херня полная не то надо
        int temp=0;
        int res=0;
        int max = 0;
        for (int i = 0; i < array.length-boostLength ; i++) {
            for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            }
            if (max<temp) {
                max=temp;
                res=i;
                temp = 0;
            }
            else {temp=0;}
        }
        for (int i = res; i <res+boostLength ; i++) {
            array[i]=1;
        }
        return array;
    }

    static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }

}


import java.util.Scanner;

public class Main2 {
    public static void main(String[] args) {
        Scanner read = new Scanner(System.in);      //читаем
        int lectionLength = read.nextInt();
        int spellTime = read.nextInt();
        int[] theorems = new int[lectionLength];
        int[] sleepingTable= new int[lectionLength];
        for (int i = 0; i < lectionLength; i++) {
            theorems[i]=read.nextInt();
        }
        for (int i = 0; i < lectionLength; i++) {
            sleepingTable[i]=read.nextInt();
        }                                           //больше не читаем
       // System.out.println(theoremCount(maxEffect(sleepingTable,theorems,spellTime),theorems));
        System.out.println(maxEffect(sleepingTable,theorems,spellTime));
    }
    static int maxEffect (int[] array, int[] values, int boostLength) {
        int temp=0;
        int res=0;
        int max = 0;
        for (int i = 0; i < boostLength; i++) {
            if (array[i]==1) {res+=values[i];}
            temp-=(values[i]*(array[i]-1));
        }
        for (int i = boostLength; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
           /* for (int j = 0; j < boostLength; j++) {
                temp-=(values[i+j]*(array[i+j]-1));
            } */
            temp-=(values[i]*(array[i]-1));
            temp+=(values[i-boostLength]*(array[i-boostLength]-1));
            if (max<temp) {
                max=temp;
            }
        }
        return res+max;
    }

  /*  static int theoremCount (int[] array, int[] values) {
        int res=0;
        for (int i = 0; i < array.length ; i++) {
            if (array[i]==1) {res+=values[i];}
        }
        return res;
    }*/

}


import java.io.PrintWriter;
import java.util.Scanner;

public class cf961b {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//1,000,000,000

		int n = sc.nextInt();
		int k =sc.nextInt();

		int[] theorems = new int[n];
		int[] awake = new int[n];

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

		int max = 0;
		for (int i =0; i < k; i++) {
			max += awake[i] == 0 ? theorems[i] : 0;
		}
		int cur = max;
		for (int i = k+1; i <= n-k+1; i++) {
			cur += awake[i] == 0 ? theorems[i] : 0;
			cur -= awake[i-k] == 0 ? theorems[i-k] : 0;
			max = Math.max(max, cur);
		}

		int sum =0 ;
		for (int i = 0; i < n; i++) {
			if (awake[i] == 1) {
				sum += theorems[i];
			}
		}

		System.out.println(sum + max);

	}

}


import java.io.PrintWriter;
import java.util.Scanner;

public class cf961b {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int k =sc.nextInt();

		int[] theorems = new int[n];
		int[] awake = new int[n];

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

		int max = 0;
		for (int i =0; i <= k; i++) {
			max += awake[i] == 0 ? theorems[i] : 0;
		}
		int cur = max;
		for (int i = k+1; i < n; i++) {
			cur += awake[i] == 0 ? theorems[i] : 0;
			cur -= awake[i-k] == 0 ? theorems[i-k] : 0;
			max = Math.max(max, cur);
		}

		int sum =0 ;
		for (int i = 0; i < n; i++) {
			if (awake[i] == 1) {
				sum += theorems[i];
			}
		}

		System.out.println(sum + max);

	}

}


import java.io.PrintWriter;
import java.util.Scanner;

public class cf961b {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		//1,000,000,000

		int n = sc.nextInt();
		int k =sc.nextInt();

		int[] theorems = new int[n];
		int[] awake = new int[n];

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

		int max = 0;
		for (int i =0; i < k; i++) {
			max += awake[i] == 0 ? theorems[i] : 0;
		}
		int cur = max;
		for (int i = k; i < n; i++) {
			cur += awake[i] == 0 ? theorems[i] : 0;
			cur -= awake[i-k] == 0 ? theorems[i-k] : 0;
			max = Math.max(max, cur);
		}

		int sum =0 ;
		for (int i = 0; i < n; i++) {
			if (awake[i] == 1) {
				sum += theorems[i];
			}
		}

		System.out.println(sum + max);

	}

}


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

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        int[] t=new int[n];
        for(int i=0;i<n;i++) t[i]=sc.nextInt();

        long ans=0;
        long curr=0;
        int i=0;
        for(i=0;i<k;i++) curr += a[i];
        ans=curr;

        i=0;
        for(;i<n-k;i++){
            if(t[i]==1) curr-=a[i];
            curr += a[i+k];
            ans=Math.max(ans,curr);
        }

        System.out.println(ans);
    }
}


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

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        int[] t=new int[n];
        for(int i=0;i<n;i++) t[i]=sc.nextInt();

        long ans=0;
        for(int i=0;i<n;i++){if(t[i]==1) ans+=a[i];}
        long curr=ans;
        int i=0;
        for(i=0;i<k;i++) {if(t[i]==0) curr += a[i];}
        ans=Math.max(ans,curr);

        i=0;
        for(;i<n-k;i++){
            if(t[i]==0) curr-=a[i];
            if(t[i+k]==0) curr += a[i+k];
            ans=Math.max(ans,curr);
        }

        System.out.println(ans);
    }
}


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

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n=sc.nextInt();
        int k=sc.nextInt();

        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        int[] t=new int[n];
        for(int i=0;i<n;i++) t[i]=sc.nextInt();

        long ans=0;
        long curr=0;
        int i=0;
        for(i=0;i<k;i++) curr += a[i];
        ans=curr;

        i=0;
        for(;i<n-k;i++){
            if(t[i]==0) curr-=a[i];
            curr += a[i+k];
            ans=Math.max(ans,curr);
        }

        System.out.println(ans);
    }
}