#include <bits/stdc++.h>
using namespace std;
struct haha {
  long long p, c, id;
} a[100100];
bool cmp(const haha aa, const haha bb) { return aa.p < bb.p; }
long long n, i, j, k, wa[100100];
priority_queue<long long, vector<long long>, greater<long long> > qu;
int main() {
  scanf("%I64d%I64d", &n, &k);
  for (i = 0; i < n; i++) scanf("%I64d", &a[i].p);
  for (i = 0; i < n; i++) scanf("%I64d", &a[i].c);
  if (k == 0) {
    for (i = 0; i < n; i++) printf("%I64d ", a[i].c);
    printf("\n");
    return 0;
  }
  for (i = 0; i < n; i++) a[i].id = i;
  sort(a, a + n, cmp);
  long long s = 0ll;
  for (i = 0; i < n; i++) {
    if (qu.size() >= k) {
      if (qu.top() < a[i].c) {
        wa[a[i].id] = s + a[i].c;
        s -= qu.top();
        qu.pop();
        qu.push(a[i].c);
        s += a[i].c;
      } else
        wa[a[i].id] = s + a[i].c;
    } else {
      wa[a[i].id] = s + a[i].c;
      qu.push(a[i].c);
      s += a[i].c;
    }
  }
  for (i = 0; i < n; i++) printf("%I64d ", wa[i]);
  printf("\n");
}
