#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int> > v;
map<long long int, long long int> m;
int main() {
  long long int n, k, i, j, p, c;
  cin >> n >> k;
  vector<long long int> ans(n, 0);
  for (i = 0; i < n; i++) {
    cin >> p;
    v.push_back(make_pair(p, 0ll));
    m[p] = i;
  }
  priority_queue<long long int, vector<long long int>, greater<long long int> >
      pq;
  for (i = 0; i < n; i++) {
    cin >> c;
    v[i].second = c;
  }
  if (k == 0) {
    for (i = 0; i < n; i++) cout << v[i].second << " ";
    cout << endl;
    return 0;
  }
  sort(v.begin(), v.end());
  long long int cnt = 0;
  ans[m[v[0].first]] = v[0].second;
  for (i = 1; i < n; i++) {
    if (i > k && (pq.top()) < (v[i - 1].second)) {
      cnt += (v[i - 1].second);
      cnt -= (pq.top());
      pq.pop();
      pq.push(v[i - 1].second);
    } else if (i <= k) {
      pq.push(v[i - 1].second);
      cnt += v[i - 1].second;
    }
    ans[m[v[i].first]] = cnt + (v[i].second);
  }
  for (i = 0; i < n; i++) cout << ans[i] << " ";
  cout << endl;
  return 0;
}
