#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  pair<long long, pair<long long, int> > p[n];
  for (int i = 0; i < n; i++) cin >> p[i].first;
  for (int i = 0; i < n; i++) {
    cin >> p[i].second.first;
    p[i].second.second = i;
  }
  sort(p, p + n);
  multiset<long long> s;
  long long ans[n], x = 0;
  for (int i = 0; i < n; i++) {
    int t = p[i].second.second;
    long long c = p[i].second.first;
    ans[t] = c + x;
    if ((int)s.size() < k) {
      s.insert(c);
      x += c;
    } else {
      if (s.size() != 0 && c > *s.begin()) {
        x -= *s.begin();
        s.erase(s.begin());
        s.insert(c);
        x += c;
      }
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
