#include<cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1100;
int weight[maxn];
int np,ng;
int r[maxn];
int main()
{
int u;
queue<int> q;
scanf("%d %d",&np,&ng);
for(int i = 0; i < np; i++)
{
scanf("%d",&weight[i]);
}
for(int i = 0; i < np; i++)
{
scanf("%d",&u);
q.push(u);
}
int temp = np , group;
while(q.size() != 1)
{
if(temp % ng == 0) group = temp / ng;
else group = temp / ng + 1;
for(int i = 0; i < group; i++)
{
int max = q.front();
for(int j = 0; j < ng; j++)
{
if(i * ng + j >= temp) break;
int f = q.front();
if(weight[f] > weight[max])
{
max = f;
}
r[f] = group + 1;
q.pop();
}
q.push(max);
}
temp = group;
}
r[q.front()] = 1;
for(int i = 0;i < np; i++)
{
if(i != 0) printf(" ");
printf("%d",r[i]);
}
return 0;
}