#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned ll;
const int N=2.5e5+10;
const ll INF=1e18;
int n,m,a[N],b[N];
vector<int>num;
int root[N];
namespace SGT{
const int K=N*20;
struct node{
int ls,rs,cnt;
ll sum;
}t[K];
int k;
void insert(int &rt,int x,int l=0,int r=num.size()-1){
t[++k]=t[rt],rt=k,t[rt].cnt++,t[rt].sum+=num[x];
if(l==r)return;
int mid=(l+r)>>1;
if(x<=mid)insert(t[rt].ls,x,l,mid);
else insert(t[rt].rs,x,mid+1,r);
}
ll query(int r1,int r2,int k,int l=0,int r=num.size()-1){
if(l==r)return 1ll*k*num[l];
int mid=(l+r)>>1,cnt=t[t[r2].rs].cnt-t[t[r1].rs].cnt;
if(k<=cnt)return query(t[r1].rs,t[r2].rs,k,mid+1,r);
return query(t[r1].ls,t[r2].ls,k-cnt,l,mid)+t[t[r2].rs].sum-t[t[r1].rs].sum;
}
}
ll pre[N];
ll calc(int l,int r){
ll ans=pre[l-1]-pre[r]+SGT::query(root[l-1],root[r],m);
// debug("calc",l,r,ans);
return ans;
}
ll ans[N];
int cur[N];
void solve(int l,int r,int L,int R){
if(l>r)return;
int mid=(l+r)>>1;
for(int i=max(L,mid+m-1);i<=R;i++){
ll val=calc(mid,i);
if(val>ans[mid])ans[mid]=val,cur[mid]=i;
}
solve(l,mid-1,L,cur[mid]);
solve(mid+1,r,cur[mid],R);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1;i<=n;i++)scanf("%d",&b[i]);
num=ary(b,1,n);
sort(all(num)),num.erase(unique(all(num)),num.end());
for(int i=1;i<=n;i++){
b[i]=lower_bound(all(num),b[i])-num.begin();
}
for(int i=1;i<=n;i++){
SGT::insert(root[i]=root[i-1],b[i]);
}
for(int i=1;i<=n;i++)pre[i]=pre[i-1]+a[i];
fill(ans+1,ans+1+n-m+1,-INF);
solve(1,n-m+1,m,n);
ll tar=*max_element(ans+1,ans+1+n-m+1);
printf("%lld\n",tar);
debug(ary(ans,1,n-m+1));
for(int i=1;i<=n;i++)putchar('0');
puts("");
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif