#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, res = 0, i, c, arr[100005], sum = 0;
  cin >> n >> k;
  vector<pair<long long int, long long int> > vp;
  priority_queue<long long int> pq;
  map<long long int, long long int> ma;
  vector<long long int> v1, v2;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v1.push_back(a);
  };
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    v2.push_back(a);
  };
  for (int i = 0; i < n; i++) {
    vp.push_back(make_pair(v1[i], v2[i]));
  }
  sort(vp.begin(), vp.end());
  for (i = 0; i < n; i++) {
    sum += vp[i].second;
    if (pq.size() > (k)) {
      sum += pq.top();
      pq.pop();
    }
    if (vp[i].second != 0) pq.push((-1) * vp[i].second);
    ma[vp[i].first] = sum;
  }
  for (i = 0; i < n; i++) cout << ma[v1[i]] << " ";
}
