#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int maxn = 1e5 + 10;
struct node {
  int p, c, id;
} a[maxn];
bool cmp(node a1, node a2) { return a1.p < a2.p; }
long long sum, ans[maxn];
int t[maxn], cnt;
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &a[i].p), a[i].id = i;
  for (int i = 0; i < n; i++) scanf("%d", &a[i].c);
  if (k == 0) {
    for (int i = 0; i < n; i++) printf("%d ", a[i].c);
    return 0;
  }
  sort(a, a + n, cmp);
  for (int i = 0; i < n; i++) {
    int l = i, r = i;
    while (r < n - 1 && a[r + 1].p == a[l].p) r++;
    for (int j = l; j <= r; j++) {
      ans[a[j].id] = 1ll * a[j].c + sum;
    }
    for (int j = l; j <= r; j++) {
      if (cnt < k) {
        t[cnt++] = a[j].c;
        sum += 1ll * a[j].c;
      } else {
        int mintag = 0;
        for (int kk = 1; kk < k; kk++) {
          if (t[kk] < t[mintag]) {
            mintag = kk;
          }
        }
        if (t[mintag] < a[j].c) {
          sum += 1ll * (a[j].c - t[mintag]);
          t[mintag] = a[j].c;
        }
      }
    }
    i = r;
  }
  for (int i = 0; i < n; i++) printf("%lld ", ans[i]);
  return 0;
}
