#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<long long, pair<long long, long long> > a,
         pair<long long, pair<long long, long long> > b) {
  return a.second.first < b.second.first;
}
bool cmp1(pair<long long, pair<long long, long long> > a,
          pair<long long, pair<long long, long long> > b) {
  return a.first < b.first;
}
int main() {
  long long n, k;
  cin >> n >> k;
  long long a[n], c[n];
  pair<long long, pair<long long, long long> > p[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    cin >> c[i];
    p[i] = make_pair(i, make_pair(a[i], c[i]));
  }
  sort(p, p + n, cmp);
  multiset<long long> s;
  for (long long i = 0; i < n; i++) {
    long long res = p[i].second.second;
    if (s.size() > k) {
      set<long long>::iterator itr = s.begin();
      s.erase(itr);
    }
    if (i - 1 >= 0) {
      if (p[i].second.first == p[i - 1].second.first) {
        s.insert(p[i].second.second);
        p[i].second.second =
            p[i - 1].second.second - c[p[i - 1].first] + p[i].second.second;
        continue;
      }
    }
    long long cnt = 0;
    multiset<long long>::iterator itr;
    for (itr = s.begin(); itr != s.end(); ++itr) {
      res += *itr;
    }
    s.insert(p[i].second.second);
    p[i].second.second = res;
  }
  sort(p, p + n, cmp1);
  for (long long i = 0; i < n; i++) cout << p[i].second.second << " ";
  return 0;
}
