#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r+1)/2-1;
        bool fa = 1;
        for(int j=1;j<mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
        if(l>n/2) break;

    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<=r){

        int mid = (l+r)/2;
//        cout<<l<<" "<<r<<" "<<n/2<<" "<<mid<<endl;
        bool fa = 1;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
        if(l>n/2) break;
    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<=r){
        int mid = (l+r)/2;
        bool fa = 1;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
    }
    cout<<r<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r+1)/2-1;
        bool fa = 1;
        for(int j=1;j<mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid;
        }

        if(l>n/2) break;

    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<=r){
        int mid = (l+r)/2;
        bool fa = 1;
        for(int j=1;j<=mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid-1;
        }
       // cout<<l<<" "<<r<<endl;
    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r+1)/2-1;
        bool fa = 0;
        for(int j=1;j<mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }else{
                fa|=1;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid;
        }
        //cout<<l<<" "<<r<<endl;
        if(l>n/2) break;

    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define maxn 1000002
int dp[maxn],a[maxn];
int main(){
    int n,m;
    cin>>n>>m;
    for(int j=1;j<=n;j++){
        cin>>a[j];
    }
    sort(a+1,a+n+1);
    int l = 1,r = n;
    while(l<r){
        int mid = (l+r+1)/2-1;
        bool fa = 1;
        for(int j=1;j<mid;j++){
            if(a[n-mid+j]-a[j]<m){
                fa=0;
                break;
            }
        }
        if(fa){
            l=mid+1;
        }else{
            r=mid;
        }
       // if(l>n/2) break;

    }
    cout<<l-1<<endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3000005;
const int maxm = maxn*2;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n,k;
int a[maxn];
int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n,k;
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    int it = 0,ma = 0;
    for(int i = 0;i<n;i++){
        while(a[i]-a[it]>=k) it++;
        ma = max(ma,i-it+1);
    }
    cout<<min(n/2,n-ma)<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300005;
const int maxm = maxn*2;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n,k;
int a[maxn];
int main()
{
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    sort(a+1,a+1+n);
    int l = 0,r = n/2;
    while(l<=r){
        int mid = (l+r+1)/2;
        int ok = 1;
        for(int i = 1,j=n-mid+1;j<=n;i++,j++){
            ok&=(a[j]-a[i]>=k);
        }
        if(ok) l = mid + 1;
        else r = mid - 1;
    }
    printf("%d\n",l);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int ans=-1;
	int n,k,i,j,pts=0,A[100003],p[100003];
	int aw[100003],q[100003];
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>A[i];
    for(i=1;i<=n;i++) cin>>aw[i];
    int poss=1;
    p[1]=A[1];
    q[1]=aw[1];
    for(i=2;i<=n;i++) p[i]=p[i-1]+A[i];
    for(i=2;i<=n;i++) q[i]=q[i-1]+aw[i];
    //int MAX=p[k];
    int MIN=q[k];
    for(i=k+1;i<=n;i++)
    {
        int diff2=q[i]-q[i-k];
        if(diff2 < MIN) MIN=diff2;
    }
    //cout<<MIN<<'\n';
    for(i=k+1;i<=n;i++)
    {
        int diff1=p[i]-p[i-k];
        int diff2=q[i]-q[i-k];
        if(diff2==MIN)
        {
            if(ans<diff1) {ans=diff1; poss=i-k+1;}
        }
    }

    //cout<<'\n';
    pts+=ans;
    //cout<<pts<<'\n'
    for(i=1;i<=n;i++)
    {
        if(i==poss)
        {
            i+=(k-1);
        }
        else if(aw[i]==1) pts+=A[i];
    }
    cout<<pts;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,k,i,j,pts=0,A[100003],aw[100003],p[100003];
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>A[i];
    for(i=1;i<=n;i++) cin>>aw[i];
    int poss=-1;
    p[1]=A[1];
    for(i=2;i<=n;i++) p[i]=p[i-1]+A[i];
    int MAX=p[k];
    for(i=k+1;i<=n;i++)
    {
        int diff=p[i]-p[i-k];
        //cout<<diff<<' ';
        if(diff > MAX) {MAX=diff; poss=i-k+1;}
    }
    //cout<<'\n';
    pts+=MAX;
    //cout<<pts<<'\n';
    for(i=1;i<=n;i++)
    {
        if(i==poss)
        {
            i+=(k-1);
        }
        else if(aw[i]==1) pts+=A[i];
    }
    cout<<pts;
	return 0;
}


#include <iostream>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int a[N], q;
int optimal_pref[N], actual_pref[N];
void sol() {
    int n, ans = 0, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        optimal_pref[i] = optimal_pref[i-1] + a[i];
    }
    for(int i=1; i<=n; i++) {
        cin >> q;
        actual_pref[i] = actual_pref[i-1] + (q ? a[i] : 0);
    }
    for(int i=1; i<=n-k+1; i++) {
        int z;
        int m = actual_pref[i-1] + (z = optimal_pref[i + k - 1] - optimal_pref[i-1]);
        m += actual_pref[n] - actual_pref[i+k-1];
        //cout << z << "\n";
        ans = max(ans, m);
    }
    cout << ans << "\n";
}
int32_t main() {
	int t = 1;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//cin >> t;
	sol();
	return 0;
}


#include <iostream>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int a[N], q[N];
int optimal_pref[N], actual_pref[N];
void sol() {
    int n, ans = 0, k;
    cin >> n >> k;
    for(int i=1; i<=n; i++) {
        cin >> a[i];
        optimal_pref[i] = optimal_pref[i-1] + a[i];
    }
    for(int i=1; i<=n; i++) {
        cin >> q[i];
        actual_pref[i] = actual_pref[i-1] + (q[i] ? a[i] : 0);
    }
    for(int i=1; i<=n-k+1; i++) {
        int z;
        int m = actual_pref[i-1] + (z = optimal_pref[i + k - 1] - optimal_pref[i-1]);
        m += actual_pref[n] - actual_pref[i+k-1];
        //cout << z << "\n";
        ans = max(ans, m);
    }
    cout << ans << "\n";
}
int32_t main() {
	int t = 1;
	//cin >> t;
	while(t--) sol();
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,k,i,j,pts=0,A[100003],aw[100003],p[100003];
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>A[i];
    for(i=1;i<=n;i++) cin>>aw[i];
    int poss=1;
    p[1]=A[1];
    for(i=2;i<=n;i++) p[i]=p[i-1]+A[i];
    int MAX=p[k];
    for(i=k+1;i<=n;i++)
    {
        int diff=p[i]-p[i-k];
        //cout<<diff<<' ';
        if(diff > MAX) {MAX=diff; poss=i-k+1;}
    }
    //cout<<'\n';
    pts+=MAX;
    //cout<<pts<<'\n';
    for(i=1;i<=n;i++)
    {
        if(i==poss)
        {
            i+=(k-1);
        }
        else if(aw[i]==1) pts+=A[i];
    }
    cout<<pts;
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int ans=1;
	int n,k,i,j,pts=0,A[100003],p[100003];
	int aw[100003],q[100003];
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin>>n>>k;
	for(i=1;i<=n;i++) cin>>A[i];
    for(i=1;i<=n;i++) cin>>aw[i];
    int poss=1;
    p[0]=q[0]=0;
    p[1]=A[1];
    q[1]=aw[1];
    for(i=2;i<=n;i++) p[i]=p[i-1]+A[i];
    for(i=2;i<=n;i++) q[i]=q[i-1]+aw[i];
    //int MAX=p[k];
    int MIN=q[k];
    for(i=k+1;i<=n;i++)
    {
        int diff2=q[i]-q[i-k];
        if(diff2 < MIN) MIN=diff2;
    }
    //cout<<MIN<<'\n';
    for(i=k;i<=n;i++)
    {
        int diff1=p[i]-p[i-k];
        int diff2=q[i]-q[i-k];
        if(diff2==MIN)
        {
            if(ans<diff1) {ans=diff1; poss=i-k+1;}
        }
    }

    //cout<<'\n';
    pts+=ans;
    //cout<<pts<<'\n'
    for(i=1;i<=n;i++)
    {
        if(i==poss)
        {
            i+=(k-1);
        }
        else if(aw[i]==1) pts+=A[i];
    }
    cout<<pts;
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define MAX_N 100010
int a[MAX_N], t[MAX_N];

int main() {
    int n, k, i;
    long long sliding_window = 0, sum = 0, temp = 0;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", t + i);
        if (t[i] == 1)sum += a[i];
    }

    for (int i = 0; i < n; i++) {
        if (!t[i])temp += a[i];
        if (i - k >= 0 && !t[i - k])temp -= a[i - k];
        sliding_window = (temp > sliding_window) ? temp : sliding_window;

    }
    printf("%I64d\n", sum + sliding_window);
    system("pause");
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define MAX_N 100010
int a[MAX_N], t[MAX_N];

int main() {
    int n, k, i;

    while(~scanf("%d %d", &n, &k))
    {long long sliding_window = 0, sum = 0, temp = 0;
        for (int i = 0; i < n; i++) {
        scanf("%d", a + i);
    }
    for (int i = 0; i < n; i++) {
        scanf("%d", t + i);
        if (t[i] == 1)sum += a[i];
    }

    for (int i = 0; i < n; i++) {
        if (!t[i])temp += a[i];
        if (i - k >= 0 && !t[i - k])temp -= a[i - k];
        sliding_window = (temp > sliding_window) ? temp : sliding_window;

    }
    printf("%I64d\n", sum + sliding_window);

    }

    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    long long a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {memset(s,0,sizeof(s));
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].t);
        }

        long long Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<=n;i++)
        {long long sum=0;
            if(s[i].t==0)
            {
                for(int j=i;(j<=((i+k-1)<n?(i+k-1):n))||(s[j].t==1);j++)
                {
                    sum+=s[j].a;
                }
                for(int j=i-1;j>0&&s[j].t==1;j--)
                {
                    sum+=s[j].a;
                }
            }
            Max=Max>sum?Max:sum;
        }
        printf("%lld\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    long long a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {memset(s,0,sizeof(s));
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].t);
        }

        long long Max=0;
        s[0].a=0;
        s[0].t=0;

        for(int i=1;i<=n;i++)
        {long long sum=0;
            if(s[i].t==0)
            {
                for(int j=i;(j<=((i+k-1)<n?(i+k-1):n))||(s[j].t==1);j++)
                {
                    sum+=s[j].a;
                }
                for(int j=i-1;(j>((i-k)>0?(i-k):0))||(s[j].t==1);j--)
                {
                    sum+=s[j].a;
                }
            }
            Max=Max>sum?Max:sum;
        }
        printf("%lld\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    int a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].t);
        }
        int sum=0;
        int Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<n;i++)
        {
            if(s[i].t==0)
            {
                for(int j=i;(j<((i+k)<n?(i+k):n))||(s[j].t==1);j++)
            {
                sum+=s[j].a;
            }
            for(int j=i-1;(j>((i-k)>0?(i-k):0))||(s[j].t==1);j--)
            {
                sum+=s[j].a;
            }

            }

            Max=Max>sum?Max:sum;
            sum=0;
        }
        printf("%d\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    int a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].t);
        }
        int sum=0;
        int Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<=n;i++)
        {
            if(s[i].t==0)
            {
                for(int j=i;(j<((i+k)<n?(i+k):n))||(s[j].t==1);j++)
            {
                sum+=s[j].a;
            }
            for(int j=i-1;(j>((i-k)>0?(i-k):0))||(s[j].t==1);j--)
            {
                sum+=s[j].a;
            }

            }

            Max=Max>sum?Max:sum;
            sum=0;
        }
        printf("%d\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    int a;
    int t;
}s[10000+9];
int main()
{
        int k,n;
        while(~scanf("%d%d",&n,&k))
        {
            for(int i=0;i<n;i++)
            {
                scanf("%d",&s[i].a);
            }
            for(int i=0;i<n;i++)
            {
                scanf("%d",&s[i].t);
            }
            int Max=0;
            int sum=0;
            for(int i=0;i<n;i++)
            {
                if(s[i].t==1)
                {
                    int str=i;
                    s[i].t=0;
                    for(int j=i;j>=(0>(i-k)?0:(i-k));j--)
                    {
                        if(s[j].t==0)
                        {
                            sum+=s[j].a;
//                            printf("L=%d ",sum);
                        }
                        else
                        {
                            break;
                        }
                    }
//                    printf("\n");
                    for(int j=i+1;j<=k+i;j++)
                    {
                        if(s[j].t==0)
                        {
                            sum+=s[j].a;
//                            printf("R=%d ",sum);
                        }
                        else
                        {
                            i=j-1;
                            break;
                        }
                    }
                    Max=sum>Max?sum:Max;
                    sum=0;
//                   printf("\n");
                    s[str].t=1;
                }
            }
            printf("%d\n",Max);
        }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    int a,t;
}s[10000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&s[i].t);
        }
        int sum=0;
        int Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<n;i++)
        {
            if(s[i].t==0)
            {
                for(int j=i;(j<((i+k)<n?(i+k):n))||(s[j].t==1);j++)
            {
                sum+=s[j].a;
            }
            for(int j=i-1;(j>((i-k)>0?(i-k):0))||(s[j].t==1);j--)
            {
                sum+=s[j].a;
            }

            }

            Max=Max>sum?Max:sum;
            sum=0;
        }
        printf("%d\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    long long a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {memset(s,0,sizeof(s));
    long long sum=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].t);
            if(s[i].t)
            {
                sum+=s[i].a;
            }
        }
//printf("sum=%lld\n",sum);
        long long Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<=n;i++)
        {
            long long temp=0;
            if(s[i].t==0)
            {
                for(int j=i;(j<=((i+k-1)<n?(i+k-1):n));j++)
                {
                    if(!s[j].t)
                    temp+=s[j].a;
//                    printf("%dFF%lld\n",j,temp);
                }

            }

            temp+=sum;
            Max=Max>temp?Max:temp;
        }
        printf("%lld\n",Max);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
struct G
{
    long long a,t;
}s[100000+9];
int  main()
{
    int k,n;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].a);
        }
        for(int i=1;i<=n;i++)
        {
            scanf("%lld",&s[i].t);
        }
        long long sum=0;
        long long Max=0;
        s[0].a=0;
        s[0].t=0;
        for(int i=1;i<=n;i++)
        {
            if(s[i].t==0)
            {
                for(int j=i;(j<((i+k)<n?(i+k):n))||(s[j].t==1);j++)
                {
                    sum+=s[j].a;
                }
                for(int j=i-1;(j>((i-k)>0?(i-k):0))||(s[j].t==1);j--)
                {
                    sum+=s[j].a;
                }
            }
            Max=Max>sum?Max:sum;
            sum=0;
        }
        printf("%lld\n",Max);
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[1000002];
int slp[1000002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (e <= n)
	{
		if(!slp[s])
			val -= arr[s];
		val += arr[e];
		ans = max(ans, val);
		s++;
		e++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[100002];
int slp[100002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (s < n || e < n)
	{
		if(!slp[s])
			val -= arr[s];
		val += arr[e];
		ans = max(ans, val);
		s++;
		e++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[1000002];
int slp[1000002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < n; i++)
		if (slp[i])
			val += arr[i];

	for (int i = 0; i < k; i++)
		if(!slp[i])
			val += arr[i];

	ans = max(ans, val);
	while (s < n)
	{
		if(!slp[s])
			val -= arr[s];
		if(!slp[e])
			val += arr[e];

		ans = max(ans, val);
		s++;
		e++;
	//	cout << "s :: " << s << " e :: " << e << " val :: " << val << " ans :: " << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[1000002];
int slp[1000002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (s < n && e < n)
	{
		if(!slp[s])
			val -= arr[s];
		val += arr[e];
		ans = max(ans, val);
		s++;
		e++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[1000002];
int slp[1000002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (s < n)
	{
		if(!slp[s])
			val -= arr[s];
		val += arr[e];

		ans = max(ans, val);
		s++;
		e++;
	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[1002];
int slp[1002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (s < n || e < n)
	{
		val -= arr[s];
		val += arr[e];
		if (val > ans)
		{
			ans = val;
			pos.first = s;
			pos.second = e;
		}
		s++;
		e++;
//		cout << " s :: " << s << " e :: " << e << " val :: " << val << " ans :: " << ans << endl;
	}
//	cout << " firs t:: " << pos.first << " se c :: " << pos.second << endl;
	for (int i = 0; i < n; i++)
	{
		if (!(pos.first < i && i <= pos.second))
			if (slp[i])
			{
			//	cout << " i :: " << i << endl;
				ans += arr[i];
			}

	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[100002];
int slp[100002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (e < n)
	{
		val -= arr[s];
		val += arr[e];
		if (val > ans)
		{
			ans = val;
			pos.first = s + 1;
			pos.second = e + 1;
		}
		s++;
		e++;
	//	cout << " s :: " << s << " e :: " << e << " val :: " << val << " ans :: " << ans << endl;
	}

	//cout << " firs t:: " << pos.first << " se c :: " << pos.second << endl;
	for (int i = 0; i < n; i++)
	{
		if (!(pos.first <= i && i <= pos.second))
			if (slp[i])
			{
			//	cout << " i :: " << i << endl;
				ans += arr[i];
			}

	}
	cout << ans << endl;
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <memory.h>
#include <string>
#include <queue>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

ll arr[100002];
int slp[100002];
pii pos;
int main()
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 0; i < n; i++)
		scanf("%lld", &arr[i]);
	for (int i = 0; i < n; i++)
		scanf("%d", &slp[i]);

	ll ans = 0;
	int s = 0, e = k;
	ll val = 0;
	for (int i = 0; i < k; i++)
		val += arr[i];
	ans = max(ans, val);
	while (s < n || e < n)
	{
		val -= arr[s];
		val += arr[e];
		if (val > ans)
		{
			ans = val;
			pos.first = s;
			pos.second = e;
		}
		s++;
		e++;
//		cout << " s :: " << s << " e :: " << e << " val :: " << val << " ans :: " << ans << endl;
	}
//	cout << " firs t:: " << pos.first << " se c :: " << pos.second << endl;
	for (int i = 0; i < n; i++)
	{
		if (!(pos.first < i && i <= pos.second))
			if (slp[i])
			{
			//	cout << " i :: " << i << endl;
				ans += arr[i];
			}

	}
	cout << ans << endl;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, suma, maxx = 0, j = 0, suma1 = 0, donja, gornja;
	cin>>n>>k;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(minute[i] == 0 && i<=n-k+1)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}

		}
		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(minute[i] == 0 && i<=n-k+1)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}

		}
		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(i<n-k+1 && minute[i] == 0)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				if(!minute[i+j])
					suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
			}
		}

		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n,m, index_a;
	vector<long long int> a,b;
	vector<long long int> umn;
	vector<long long int>::iterator indeks;
	long long int broj, maxx, max2;
	cin>>n>>m;
	for(int i = 0;i<n;i++)
	{
		cin>>broj;
		a.push_back(broj);
	}
	for(int i = 0;i<m;i++)
	{
		cin>>broj;
		b.push_back(broj);
	}
	maxx = a[0]*b[0];
	max2 = a[0]*b[1];
	index_a = 0;
	for(int i = 0;i<n;i++)
	for(int j = 0;j<m;j++)
	{
		if(a[i]*b[j]>maxx)
		{
			index_a = i;
			maxx = a[i]*b[j];
		}
	}
	max2 = -1000000000000000000;
	for(int i = 0;i<n;i++)
	for(int j = 0;j<m;j++)
	{
		if(a[i]*b[j]>max2 && i != index_a)
		{
			max2 = a[i]*b[j];
		}
	}
	cout<<max2;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(i<=n-k+1 && minute[i] == 0)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}
		}

		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, suma, maxx = 0, j = 0, suma1 = 0, donja, gornja;
	cin>>n>>k;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(minute[i] == 0 && i+k+1<n)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}

		}
		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(i<=n-k+1)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}
		}

		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, suma, maxx = 0, j = 0, suma1 = 0, donja, gornja;
	cin>>n>>k;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{
		if(minute[i] == 0 && i+k<n)
		{
			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}

		}
		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];
	suma = 0;
	for(j = 0;j<k&&j<n;j++)
				if(!minute[j])
					suma+=teoremi[j];
	maxx=suma;
	if(minute[0] == 1)
		suma1+=teoremi[0];
	for(int i = 1;i<n;i++)
	{
		if(!minute[i-1])
			suma-=teoremi[i-1];
		if(i+k-1<n&&!minute[i+k-1])
			suma+=teoremi[i+k-1];

			/*for(j = 0;j<k&&j+i<n;j++)
				if(!minute[i+j])
					suma+=teoremi[i+j];
					*/
			if(suma>maxx)
			{
				maxx = suma;
			}

		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	cout<<maxx+suma1;
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
	int n,k, j = 0, donja, gornja;
	cin>>n>>k;
	long int suma1 = 0, maxx = 0, suma;
	int teoremi[100000], minute[100000];
	for(int i = 0;i<n;i++)
	cin>>teoremi[i];
	for(int i = 0;i<n;i++)
	cin>>minute[i];

	for(int i = 0;i<n;i++)
	{

			suma = 0;
			for(j = 0;j<k;j++)
				suma+=teoremi[i+j];
			if(suma>maxx)
			{
				maxx = suma;
				donja = i;
				gornja = i+j;
			}

		if(minute[i] == 1)
		suma1+=teoremi[i];
	}
	for(int i = donja;i<gornja;i++)
	if(minute[i] == 1)
	suma1-=teoremi[i];
	cout<<maxx+suma1;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100000;
long long n, k, a[MAXN], t[MAXN], ans1 = 0, ans2 = 0, tmp = 0, mx;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(long long i = 0; i < n; i ++)
        cin >> a[i];
    for(long long i = 0; i < n; i ++){
        cin >> t[i];
        ans1 += t[i] * a[i];
        a[i] *= abs(t[i] - 1);
    }
    for(long long i = k - 1; i < n; i ++){
        tmp = ans2;
        ans2 = 0;
        for(long long j = i - k + 1; j <= i; j ++)
            ans2 += a[j];
        mx = max(tmp, ans2);
    }
    cout << mx + ans1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {

	int n, k;
	cin >> n >> k;

	vector <int> a[n];
	vector <int> t[n];

	int ans = 0;

	for (int i = 0; i < n; ++i)
		cin >> a[i];

	for (int i = 0; i < n; ++i)
		cin >> t[i];

	vector <int> pr[n];
	for (int i = 0; i < n; ++i) {
		pr[i] += pr[i - 1];
		if (t[i] == 0) pr[i] += a[i];
		else ans += a[i];
	}

	int add = 0;
	for (int i = k - 1; i < n; ++i) {
	    int m = 0;
	    if(i >= k) m = pr[i-k];
		add = max(add, pr[i] - m);
	}

	cout << ans + add;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100000;
int n, k, a[MAXN], t[MAXN], ans1 = 0, ans2 = 0, tmp = 0, mx;

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    for(int i = 0; i < n; i ++){
        cin >> t[i];
        ans1 += t[i] * a[i];
        a[i] *= abs(t[i] - 1);
    }
    for(int i = k - 1; i < n; i ++){
        tmp = ans2;
        ans2 = 0;
        for(int j = i - k + 1; j <= i; j ++)
            ans2 += a[j];
        mx = max(tmp, ans2);
    }
    cout << mx + ans1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;
long long n, k, a[MAXN], t[MAXN], ans1 = 0, ans2 = 0, tmp = 0, mx;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(long long i = 0; i < n; i ++)
        cin >> a[i];
    for(long long i = 0; i < n; i ++){
        cin >> t[i];
        ans1 += t[i] * a[i];
        a[i] *= abs(t[i] - 1);
    }
    for(long long i = k - 1; i < n; i ++){
        tmp = ans2;
        ans2 = 0;
        for(long long j = i - k + 1; j <= i; j ++)
            ans2 += a[j];
        mx = max(tmp, ans2);
    }
    cout << mx + ans1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;
long long n, k, a[MAXN], ans1 = 0, ans2 = 0, tmp = 0, mx;
bool t[MAXN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(long long i = 0; i < n; i ++)
        cin >> a[i];
    for(long long i = 0; i < n; i ++){
        cin >> t[i];
        ans1 += t[i] * a[i];
        a[i] *= (!t[i]);
    }
    for(long long i = k - 1; i < n; i ++){
        tmp = ans2;
        ans2 = 0;
        for(long long j = i - k + 1; j <= i; j ++)
            ans2 += a[j];
        mx = max(tmp, ans2);
    }
    cout << mx + ans1;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int a[MAXN];
int par[MAXN];
bool t[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    par[0] = 0;
    long long s = 0;
    for(int  i = 1; i <= n; i++)
        cin >> a[i];
    for(int  i = 1; i <= n; i++){
        cin >> b[i];
        if(b[i] != 1){
            par[i] = par[i - 1] + a[i];
        }
        else{
            s += a[i];
            par[i] = par[i - 1];
        }
    }
    int j = k, _max = -1, ans = s;
    while(j <= n){
        if(par[j] - par[j - k] > _max){
            _max = par[j] - par[j - k];
            s = _max;
        }
        j ++;
    }
    cout << s + ans<< endl;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int a[MAXN];
int par[MAXN];
bool t[MAXN];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    par[0] = 0;
    long long s = 0;
    for(int  i = 1; i <= n; i++)
        cin >> a[i];
    for(int  i = 1; i <= n; i++){
        cin >> t[i];
        if(!t[i]){
            par[i] = par[i - 1] + a[i];
        }
        else{
            s += a[i];
            par[i] = par[i - 1];
        }
    }
    int j = k, _max = -1, ans = s;
    while(j <= n){
        if(par[j] - par[j - k] > _max){
            _max = par[j] - par[j - k];
            s = _max;
        }
        j ++;
    }
    cout << s + ans<< endl;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100000;
int n, k, a[MAXN], t[MAXN], ans1 = 0, ans2 = 0, tmp = 0, mx;

int main()
{
    cin >> n >> k;
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    for(int i = 0; i < n; i ++){
        cin >> t[i];
        ans1 += t[i] * a[i];
        a[i] *= abs(t[i] - 1);
    }
    for(int i = k - 1; i < n; i ++){
        tmp = ans2;
        ans2 = 0;
        for(int j = i - k + 1; j <= i; j ++)
            ans2 += a[j];
        mx = max(tmp, ans2);
    }
    cout << mx + ans1;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;

  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {
   if(zeroz[i]+k-1>=n)break;
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
    else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]]);
//cout<<max<<endl;
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;
  zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz[i]=i;

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n)
   max=abs(sum[n-1]-sum[zeroz[i]-1]);
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]]);
//cout<<max<<endl;
}
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;

  vector<int>min;
      min.resize(n);

   vector<int>stat;
        stat.resize(n);

  for(int i=0; i<n; i++)
  cin>>min[i];

      for(int i=0; i<n; i++)
      cin>>stat[i];

  vector<int> zeroz;
  //zeroz.resize(n);

  for(int i=0; i<n; i++)
    if(stat[i]==0)
       zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    if(!stat[0])
    sum[0]=min[0];
    else sum[0]=0;
    for(int i=1; i<n; i++)
    // cout<<min[i]<<" "
    if(stat[i]==0)
     sum[i]=min[i]+sum[i-1];
     else sum[i]=sum[i-1];

    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;

    if(!zeroz. empty()){

  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n)
   {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=n;
    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<" "<<maxx<<endl;
    }
 if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {

   if(stat[i]==1)
    summ+=min[i];
  }
 //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;

  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;
  //zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(stat[i]==0)
  zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n) {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;

    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
//   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>=begin &&i<=end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
  //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;

  vector<int>min;
      min.resize(n);

   vector<int>stat;
        stat.resize(n);

  for(int i=0; i<n; i++)
  cin>>min[i];

      for(int i=0; i<n; i++)
      cin>>stat[i];

  vector<int> zeroz;
  //zeroz.resize(n);

  for(int i=0; i<n; i++)
    if(stat[i]==0)
       zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    // cout<<min[i]<<" "
     sum[i]=min[i]+sum[i-1];

    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;

    if(!zeroz. empty()){

  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n)
   {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=n;
    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
//   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<=end)
    continue;
    else if(stat[i]==1)
    summ+=min[i];
  }
 //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;

  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {
   if(zeroz[i]+k-1>=n)break;
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
    else    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]]);
//cout<<max<<endl;
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;
  //zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(stat[i]==0)
  zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n) {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;

    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
//   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>=begin &&i<=end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;
  //zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(stat[i]==0)
  zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n) {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;

    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
//   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;

  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n)
   max=abs(sum[n-1]-sum[zeroz[i]-1]);
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]]);
//cout<<max<<endl;
}
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;

  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz.push_back(i);

    vector<int>sum;
    sum.resize(n);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
  for(int i=0; i<n; i++)
  {

    if(zeroz[i]+k-1>=n)break;
  if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
    else    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]]);
//cout<<max<<endl;
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;

  vector<int>min;
      min.resize(n);

   vector<int>stat;
        stat.resize(n);

  for(int i=0; i<n; i++)
  cin>>min[i];

      for(int i=0; i<n; i++)
      cin>>stat[i];

  vector<int> zeroz;
  zeroz.resize(n);

int j=0;
  for(int i=0; i<n; i++)
    if(stat[i]==0){
       zeroz[j]=i;
      j++;
    }
    //zeroz.resize(j+1);

    vector<int>sum;
    sum.resize(100000);

    if(!stat[0])
    sum[0]=min[0];
    else sum[0]=0;

    for(int i=1; i<n; i++)
    // cout<<min[i]<<" "
    if(stat[i]==0)
     sum[i]=min[i]+sum[i-1];
     else sum[i]=sum[i-1];

    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;

    if(!zeroz. empty()){

  for(int i=0; i<n; i++)
  {
 //cout<<zeroz[i]<<" ";
   if(zeroz[i]+k-1>=n)
   {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=n;
    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<" "<<maxx<<endl;
    }
 if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {

   if(stat[i]==1)
    summ+=min[i];
  }
 //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  //cout<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

 /* if(n==k)
  {
    long long ans=0;
    for(int i=0; i<n; i++)
    ans+=min[i];
  return 0;
  }*/

  vector<int> zeroz;
  //zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(stat[i]==0)
  zeroz.push_back(i);

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n) {
  max=abs(sum[n-1]-sum[zeroz[i]-1]);
     if(max>maxx)
    {
      maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;

    }

     break;
   }
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
//   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<=end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 //cout<<summ<<endl;
  //cout<<maxx<<" "<<begin<<" "<<end<<endl;
  cout<<maxx+summ<<endl;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
  int n,k;
  cin>>n>>k;
  vector<int>min;
  min.resize(n);
   vector<int>stat;
stat.resize(n);
  for(int i=0; i<n; i++)
  {
  cin>>min[i];
  }
  for(int i=0; i<n; i++)
  cin>>stat[i];

  vector<int> zeroz;
  zeroz.resize(n);
  for(int i=0; i<n; i++)
    if(!stat[i])
    zeroz[i]=i;

    vector<int>sum;
    sum.resize(100000);

    sum[0]=min[0];

    for(int i=1; i<n; i++)
    {
     // cout<<min[i]<<" ";
    sum[i]=min[i]+sum[i-1];
    }
    //cout<<endl;
    long long max=0,maxx=0;

    int begin=0,end=0;
    if(!zeroz. empty()){
  for(int i=0; i<n; i++)
  {

   if(zeroz[i]+k-1>=n)
   max=abs(sum[n-1]-sum[zeroz[i]-1]);
   else
   {
   if(zeroz[i]!=0)
    max=abs(sum[zeroz[i]+k-1]-sum[zeroz[i]-1]);
        else if(zeroz[i]==0&&k==1)max=sum[zeroz[i]];
    else max=sum[zeroz[i]+k-1];
//cout<<max<<endl;
    }
    //cout<<max<<endl;
   if(max>maxx)
    {maxx=max;
    begin=zeroz[i]; end=zeroz[i]+k-1;    }
  }

    }

  long long summ=0;

  for(int i=0; i<n; i++)
  {
    if(i>begin &&i<end)
    continue;
    else if(stat[i])
    summ+=min[i];
  }
 // cout<<summ<<endl;
  //cout<<maxx<<endl;
  cout<<maxx+summ<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = INT_MIN;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    // for(int i=0;i<n;i++){
    //     cout<<sum[i]<<"\n";
    // }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                prev = 0;
            int x = sum[i + k - 1] -prev;
            // cout<<sum[i+k-1]<<" "<<sum[i-1]<<"\n";
            mx = max(mx, x);
            prev = sum[i];
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n+2] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = 0;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                sum[i-1] = 0;
            int x = sum[i + k - 1] -sum[i-1];
            mx = max(mx, x);
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = INT_MIN;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    // for(int i=0;i<n;i++){
    //     cout<<sum[i]<<"\n";
    // }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                prev = 0;
            int x = sum[i + k - 1] -prev;
            // cout<<sum[i+k-1]<<" "<<prev<<"\n";
            mx = max(mx, x);
            prev = sum[i];
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = INT_MIN;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    // for(int i=0;i<n;i++){
    //     cout<<sum[i]<<"\n";
    // }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                sum[i-1] = 0;
            int x = sum[i + k - 1] -sum[i-1];
            // cout<<sum[i+k-1]<<" "<<sum[i-1]<<"\n";
            mx = max(mx, x);
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = INT_MIN;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    // for(int i=0;i<n;i++){
    //     cout<<sum[i]<<"\n";
    // }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                prev = 0;
            int x = sum[i + k - 1] -sum[i-1];
            // cout<<sum[i+k-1]<<" "<<sum[i-1]<<"\n";
            mx = max(mx, x);
            prev = sum[i];
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = 0;
    int prev=0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;

        }else{
             if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }

    }
    // for(int i=0;i<n;i++){
    //     cout<<sum[i]<<"\n";
    // }
    prev =0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                sum[i + k - 1] = sum[n - 1];
            if (i - 1 < 0)
                sum[i-1] = 0;
            int x = sum[i + k - 1] -sum[i-1];
            // cout<<sum[i+k-1]<<" "<<sum[i-1]<<"\n";
            mx = max(mx, x);
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define mod 1000000007
#define inf 1e18
#define ps(x, y) fixed << setprecision(y) << x
#define mk(arr, n, type) type *arr = new type[n];
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    mk(a, n, int);
    int sum[n + 2] = {0};
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vi v;
    mk(t, n, int);
    int s = 0;
    int mx = 0;
    int prev = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> t[i];
        if (t[i] == 1)
        {
            s += a[i];
            sum[i] = prev;
        }
        else
        {
            if (i == 0)
                sum[i] = a[i];
            else
                sum[i] = prev + a[i];
            prev = sum[i];
        }
    }
    prev = 0;
    int next = 0;
    for (int i = 0; i < n; i++)
    {
        if (!t[i])
        {
            if (i + k - 1 >= n)
                next = sum[n - 1];
            else
                next = sum[i + k - 1];

            if (i - 1 < 0)
                sum[i - 1] = 0;
            int x = next - sum[i - 1];
            mx = max(mx, x);
        }
    }
    // cout<<mx<<" ";
    cout << s + mx << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,p,q,e,f,max,s;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=-1;
	for(i=0;i<n-k+1;i++)
	{
		s=0;
		for(j=i;j<=i+k-1;j++)
		{
			s+=lec[j];
		}
		if(s>max)
		{
			max=s;
			p=i;
			q=i+k-1;
		}
	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i,j,p,q,e,f,max,s,z,g;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=-1;
	s=z=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(t[i]==0)
		  z++;
		if(i>=k-1)
		{
			if(s>max)
		   {
			  max=s;
			  p=i-k+1;
			  q=i;
			  g=z;
		   }
		   else if(s==max)
		   {
		   	if(z>g)
		   	{
		   		max=s;
			  p=i-k+1;
			  q=i;
			  g=z;

			}

		   }
		   s=s-lec[i-k+1];
		   z=0;
		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i,j,p,q,e,f,max,s,z,g;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=g=-1;
	s=z=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(t[i]==0)
		  z++;
		if(i>=k-1)
		{
			if(z>g)
			{
				//if(s>=max)
				{
					max=s;
					g=z;
					p=i-k+1;
					q=i;
				}
			}
			else if(z==g)
			{
				if(s>max)
				{
					max=s;
					g=z;
					p=i-k+1;
					q=i;
				}
			}
		   	z=0;
		   	s=s-lec[i-k+1];
		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,p,q,e,f,max,s;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=-1;
	s=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(i>=k-1)
		{
			if(s>max)
		   {
			  max=s;
			  p=i-k+1;
			  q=i;
		   }
		   s=s-lec[i-k+1];

		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i,j,max,ans,s;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	ans=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1)
		{
			ans+=lec[i];
			lec[i]=0;
		}
	}
	max=-1;
	s=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(i>=k-1)
		{
			if(s>max)
			  max=s;
			s-=lec[i-k+1];
		}
	}
	ans+=max;
	cout<<ans<<"\n";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i,j,p,q,e,f,max,s,z,g;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=g=-1;
	s=z=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(t[i]==0)
		  z++;
		if(i>=k-1)
		{
			if(z>=g)
			{
				if(s>=max)
				{
					max=s;
					g=z;
					p=i-k+1;
					q=i;
				}
			}
		   	z=0;
		   	s=s-lec[i-k+1];
		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,k,i,j,p,q,e,f,max,s,z,g;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=g=-1;
	s=z=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(t[i]==0)
		  z++;
		if(i>=k-1)
		{
			if(z>g)
			{
				//if(s>=max)
				{
					max=s;
					g=z;
					p=i-k+1;
					q=i;
				}
			}
			else if(z==g)
			{
				if(s>max)
				{
					max=s;
					g=z;
					p=i-k+1;
					q=i;
				}
			}
		   	if(t[i-k+1]==0)
		   	  z=z-1;
		   	s=s-lec[i-k+1];
		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,i,j,p,q,e,f,max,s,z,g;
	cin>>n>>k;
	int lec[n];
	for(i=0;i<n;i++)
	  cin>>lec[i];
	int t[n];
	for(i=0;i<n;i++)
	  cin>>t[i];
	max=-1;
	s=z=0;
	for(i=0;i<n;i++)
	{
		s+=lec[i];
		if(t[i]==0)
		  z++;
		if(i>=k-1)
		{
			if(s>max)
		   {
			  max=s;
			  p=i-k+1;
			  q=i;
			  g=z;
		   }
		   else if(s==max)
		   {
		   	if(z>g)
		   	{
		   		max=s;
			  p=i-k+1;
			  q=i;
			  g=z;

			}

		   }
		   s=s-lec[i-k+1];
		   z=0;
		}

	}
	//cout<<max<<"\n";
	//cout<<p<<" "<<q<<endl;
	e=0;
	for(i=0;i<n;i++)
	{
		if(t[i]==1&&(i<p||i>q))
		{
			e+=lec[i];
		}
	}
	f=e+max;
	cout<<f<<"\n";
}


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                   vector<int> v(1000005);
                   vector<int> s(1000005);

                  int main()
                {

                    int n,k;
                    scanint2(n,k);
                    long result=0;

                     for(int i=1;i<=n;i++)
                     {
                         int x;
                         scanint1(x);
                         v[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     {

                         int x;
                         scanint1(x);
                         s[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     if(s[i]) {result+=v[i]; v[i]=0; }

                     v[0]=0;
                     for(int i=1;i<=n;i++)
                        v[i]+=v[i-1];

                     long mx=0;

                     for(int i=1;i<=n+k-1;i++)
                     {
                         mx=max(mx,(long)v[i+k-1]-v[i-1]);

                     }

                     result+=mx;
                     cout<<result<<endl;

                    return 0;

                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    long v[100005];
                    int s[100005];
                    long cum[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;
                        cum[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    v[0]=0;
                    vector<long> vc;
                    long result=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(s[i]) result+=v[i];
                        if(!s[i])
                        {
                            vc.push_back(i);

                        }
                    }

                     if(vc.size()) long mx=v[vc[0]];
                    for(int i=1;i<vc.size();i++)
                    {
                         if(vc[i]<=vc[i-1]+k+1 &&vc[i-1]<=n-k+1 )
                            mx+=v[vc[i]];

                   else if(vc[i]<=n-k+1)  mx=max(v[vc[i]],mx);

                    }

                  result+=mx;
                  cout<<result<<endl;
                    return 0;
}


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    long v[100005];
                    int s[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    vector<int> vc;
                    long result=0;
                    for(int i=1;i<=n;i++)
                    {
                       if(s[i]) result+=v[i];
                       else if(i<=n-k+1 &&!s[i])
                           vc.push_back(i);

                    }

                    int last=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(!s[i]) v[i]+=last;
                        if(!s[i]) last=v[i];

                    }

                    long mx=0;
                    for(int i=0;i<vc.size();i++)
                    {

                          for(int j=vc[i]+k-1;j>=vc[i];j--)
                          {if(!s[j]){mx=max(mx,v[j]); break;}
                          }

                    }
                    result+=mx;
                    cout<<result<<endl;
                    return 0;
                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    long v[100005];
                    int s[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    vector<int> vc;
                    long result=0;
                    for(int i=1;i<=n;i++)
                    {
                       if(s[i]) result+=v[i];
                       else if(i<=n-k+1 &&!s[i])
                           vc.push_back(i);

                    }

                    int last=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(!s[i]) v[i]+=last;
                        if(!s[i]) last=v[i];

                    }

                    long mx=0;
                    for(int i=0;i<vc.size();i++)
                    {

                          long number1=0,number2=0;
                          for(int j=vc[i]+k-1;j>=1;j--)
                          {
                              if(!s[j]&&!number1){number1 =v[j]; j=vc[i]-1;}
                              else if(!s[j]&&!number2){number2 =v[j]; break;}
                          }
                          mx=max(mx,number1-number2);

                    }
                    result+=mx;
                    cout<<result<<endl;
                    return 0;
}


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    long v[100005];
                    int s[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    vector<int> vc;
                    long result=0;
                    for(int i=1;i<=n;i++)
                    {
                       if(s[i]) result+=v[i];
                       else if(i<=n-k+1 &&!s[i])
                           vc.push_back(i);

                    }

                    int last=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(!s[i]) v[i]+=last;
                        if(!s[i]) last=v[i];

                    }

                    long mx=0;
                    for(int i=0;i<vc.size();i++)
                    {

                          for(int j=vc[i]+k-1;j>=i;j--)
                          {if(!s[j]){mx=max(mx,v[j]-v[vc[i]-k-1]); break;}
                          }

                    }
                    result+=mx;
                    cout<<result<<endl;
                    return 0;
}


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    int v[100005];
                    int s[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    priority_queue<long> pq;

                    for(int i=1;i<=n-k+1;i++)
                    {
                         long result=0;
                         int counter=0;
                         for(int j=i;j<=n;j++)
                         {
                             if(counter>k) break;
                             result+=v[j];
                             counter++;
                         }

                        pq.push(result);
                    }
                    cout<<pq.top()<<endl;

                    return 0;
                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                long v[100005];
                     int s[100005];
                  int main()
                {

                    int n,k;
                    scanint2(n,k);
                    long result=0;

                     for(int i=1;i<=n;i++)
                     {
                         int x;
                         scanint1(x);
                         v[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     {

                         int x;
                         scanint1(x);
                         s[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     if(s[i]) {result+=v[i]; v[i]=0; }

                     v[0]=0;
                     for(int i=1;i<=n;i++)
                        v[i]+=v[i-1];

                     long mx=0;

                     for(int i=1;i<=n+k-1;i++)
                     {
                         mx=max(mx,v[i+k-1]-v[i-1]);

                     }

                     result+=mx;
                     cout<<result<<endl;

                    return 0;

                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    long v[100005];
                    int s[100005];
                    long cum[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;
                        cum[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    v[0]=0;
                    vector<long> vc;
                    long result=0;
                    for(int i=1;i<=n;i++)
                    {
                        if(s[i]) result+=v[i];
                        if(!s[i])
                        {
                            vc.push_back(i);

                        }
                    }

                      long mx=v[vc[0]];
                    for(int i=1;i<vc.size();i++)
                    {
                         if(vc[i]<=vc[i-1]+k+1 &&vc[i-1]<=n-k+1 )
                            mx+=v[vc[i]];

                   else if(vc[i]<=n-k+1)  mx=max(v[vc[i]],mx);

                    }

                  result+=mx;
                  cout<<result<<endl;
                    return 0;
}


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {

                    int n,k;
                    scanint2(n,k);
                    int v[n+1];
                    int  s[n+1];
                    long result=0;

                     for(int i=1;i<=n;i++)
                     {
                         int x;
                         scanint1(x);
                         v[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     {

                         int x;
                         scanint1(x);
                         s[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     if(s[i]) {result+=v[i]; v[i]=0; }

                     v[0]=0;
                     for(int i=1;i<=n;i++)
                        v[i]+=v[i-1];

                     long mx=0;

                     for(int i=1;i<=n+k-1;i++)
                     {
                         mx=max(mx,(long)v[i+k-1]-v[i-1]);

                     }

                     result+=mx;
                     cout<<result<<endl;

                    return 0;

                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                int v[100005];
                int  s[100005];
                  int main()
                {

                    int n,k;
                    scanint2(n,k);
                    long result=0;

                     for(int i=1;i<=n;i++)
                     {
                         int x;
                         scanint1(x);
                         v[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     {

                         int x;
                         scanint1(x);
                         s[i]=x;

                     }

                     for(int i=1;i<=n;i++)
                     if(s[i]) {result+=v[i]; v[i]=0; }

                     v[0]=0;
                     for(int i=1;i<=n;i++)
                        v[i]+=v[i-1];

                     long mx=0;

                     for(int i=1;i<=n+k-1;i++)
                     {
                         mx=max(mx,(long)v[i+k-1]-v[i-1]);

                     }

                     result+=mx;
                     cout<<result<<endl;

                    return 0;

                }


#include <bits/stdc++.h>
         #define ll long long
         #define scanint1(a) scanf("%d",&a)
         #define scanint2(a,b) scanf("%d %d",&a,&b)
         #define scanint3(a,b,c) scanf("%d %d %d",&a,&b,&c)
         #define scanint4(a,b,c,d) scanf("%d %d %d %d",&a,&b,&c,&d)
         #define scanint5(a,b,c,d,e) scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
         #define scanlong1(a) scanf("%ld",&a)
         #define scanlong2(a,b) scanf("%ld %ld",&a,&b)
         #define scanlong3(a,b,c) scanf("%ld %ld %ld",&a,&b,&c)
         #define scanlong4(a,b,c,d) scanf("%ld %ld %ld %ld",&a,&b,&c,&d)
         #define scanlong5(a,b,c,d,e) scanf("%ld %ld %ld %ld %ld",&a,&b,&c,&d,&e)
         #define read  freopen("input.txt","r",stdin);
         #define write  freopen("output.txt","w",stdout);

         //Convert from int to char (0 to 25 )--->(a to z) == (char)(int+97)
         //Convert from char int to int char-48
         //~ reflects 0 to 1 and 1 to 0 ; ex:: ~5 =-5
         //tester.erase(std::remove(tester.begin(), tester.end(), '0'), tester.end());
         //bool valid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }

                using namespace std;

                  int main()
                {
                    int n,k;
                    scanint2(n,k);
                    int v[100005];
                    int s[100005];
                    for(int i=1;i<=n;i++)

                    {
                        int x;
                        scanint1(x);
                        v[i]=x;

                    }
                    for(int i=1;i<=n;i++)
                    {
                        int x;
                        scanint1(x);
                        s[i]=x;

                    }

                    long result=0,mx=0;
                    for(int i=1;i<=n;i++)
                    {
                         long temp=0;
                       if(s[i]) result+=v[i];
                       else if(i<=n-k+1 &&!s[i])
                       {

                         for(int j=0;j<k;j++)
                            if(!s[i+j])
                            temp+=v[i+j];

                       }
                         mx=max(temp,mx);
                    }

                    result+=mx;
                    printf("%ld",result);

                    return 0;
                }