#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<pair<int, int> > power[N];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> p(n);
  map<int, int> mp;
  int m = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    mp[p[i]];
  }
  for (auto &it : mp) {
    it.second = m++;
  }
  for (int i = 0; i < n; i++) {
    p[i] = mp[p[i]];
  }
  for (int i = 0; i < n; i++) {
    int c;
    scanf("%d", &c);
    power[p[i]].push_back(make_pair(c, i));
  }
  vector<long long> ans(n);
  multiset<int> s;
  long long sum = 0;
  for (int p = 0; p < N; p++) {
    if (power[p].empty()) {
      continue;
    }
    int mx = 0;
    for (pair<int, int> pr : power[p]) {
      int c = pr.first, id = pr.second;
      ans[id] = sum + c;
      mx = max(mx, c);
    }
    if ((int)s.size() == k) {
      if (!s.empty()) {
        if (*s.begin() < mx) {
          sum += mx - *s.begin();
          s.erase(s.begin());
          s.insert(mx);
        }
      }
    } else if ((int)s.size() < k) {
      sum += mx;
      s.insert(mx);
    } else {
      assert(0);
    }
  }
  for (int i = 0; i < n; i++) {
    if (i > 0) {
      putchar(' ');
    }
    printf("%lld", ans[i]);
  }
  return 0;
}
