#include <iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int n,k,szabadgyerek,szabadszerep,hiszti=0;
vector<int>beosztas;
vector<pair<int,pair<int,int> > > sor;
vector<bool>valasztottszerepet;
vector<bool>valasztottak;
vector<int>maxdb;
int main()
{
cin>>n>>k;
szabadgyerek=n;
szabadszerep=k;
maxdb.resize(k+1);
beosztas.resize(n+1);
sor.resize(n);
valasztottszerepet.assign(n+1,false);
valasztottak.assign(n+1,false);
for(int i=1;i<=k;i++) cin>>maxdb[i];
for(int i=0;i<n;i++)
{
sor[i].second.second=i+1;
cin>>sor[i].second.first;
}
for(int i=0;i<n;i++) cin>>sor[i].first;
sort(sor.begin(),sor.end(),greater<>());
for(auto x:sor)
{
if(!valasztottak[x.second.first])
{
valasztottak[x.second.first]=true;
valasztottszerepet[x.second.second]=true;
--szabadgyerek;
--szabadszerep;
beosztas[x.second.second]=x.second.first;
maxdb[x.second.first]--;
continue;
}
if(szabadgyerek>szabadszerep && maxdb[x.second.first])
{
valasztottszerepet[x.second.second]=true;
--szabadgyerek;
beosztas[x.second.second]=x.second.first;
maxdb[x.second.first]--;
continue;
}
}
int index=1;
for(auto x:sor)
{
if(valasztottszerepet[x.second.second]) continue;
if(szabadgyerek==szabadszerep)
{
while(index<=k && valasztottak[index]) ++index;
valasztottak[index]=true;
--maxdb[index];
--szabadgyerek;
--szabadszerep;
valasztottszerepet[x.second.second]=true;
beosztas[x.second.second]=index;
hiszti+=x.first;
continue;
}
if(szabadgyerek>szabadszerep)
{
while(index<=k && !maxdb[index]) ++index;
if(valasztottak[index])
{
valasztottak[index]=false;
--szabadszerep;
}
--maxdb[index];
--szabadgyerek;
valasztottszerepet[x.second.second]=true;
beosztas[x.second.second]=index;
hiszti+=x.first;
continue;
}
}
cout<<hiszti<<endl;
for(int i=1;i<=n;i++)
{
cout<<beosztas[i]<<" ";
}
return 0;
}