#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > qu;
struct node {
  long long p, c, num, ans;
} x[100005];
bool cmpp(node a, node b) { return a.p < b.p; }
bool cmpn(node a, node b) { return a.num < b.num; }
int main() {
  int n, k;
  long long sum = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x[i].p);
    x[i].num = i;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x[i].c);
  }
  sort(x + 1, x + n + 1, cmpp);
  for (int i = 1; i <= k + 1; i++) {
    sum += x[i].c;
    x[i].ans = sum;
    qu.push(x[i].c);
  }
  for (int i = k + 2; i <= n; i++) {
    sum -= qu.top();
    qu.pop();
    qu.push(x[i].c);
    sum += x[i].c;
    x[i].ans = sum;
  }
  sort(x + 1, x + n + 1, cmpn);
  for (int i = 1; i <= n; i++) {
    printf("%lld ", x[i].ans);
  }
  return 0;
}
