#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000;
pair<int, int> pis[MAX_N];
int cs[MAX_N];
multiset<int> cset;
long long ss[MAX_N];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) scanf("%d", &pis[i].first), pis[i].second = i;
  sort(pis, pis + n);
  for (int i = 0; i < n; i++) scanf("%d", cs + i);
  long long sum = 0;
  for (int i = 0, j = 0; i < n; i++) {
    while (j < i && pis[j].first < pis[i].first) {
      int c = cs[pis[j++].second];
      cset.insert(c);
      sum += c;
      if (cset.size() > k) {
        sum -= *(cset.begin());
        cset.erase(cset.begin());
      }
    }
    int pi = pis[i].second;
    ss[pi] = sum + cs[pi];
  }
  for (int i = 0; i < n; i++) printf("%lld%c", ss[i], (i + 1 < n) ? ' ' : '\n');
  return 0;
}
