#include <bits/stdc++.h>
using namespace std;
class data {
 public:
  long long idx;
  long long pwr;
  long long coin;
};
bool srtp(data x, data y) { return x.pwr < y.pwr; }
int main() {
  long long n, k;
  cin >> n >> k;
  vector<data> v(n);
  vector<long long> str(n);
  for (long long i = 0; i < n; i++) {
    long long tem;
    cin >> tem;
    v[i].idx = i;
    v[i].pwr = tem;
  }
  for (long long i = 0; i < n; i++) {
    long long tem;
    cin >> tem;
    v[i].coin = tem;
  }
  sort(v.begin(), v.end(), srtp);
  multiset<long long> m;
  long long bck = 0;
  for (long long i = 0; i < n; i++) {
    str[v[i].idx] = bck + v[i].coin;
    bck += v[i].coin;
    m.insert(v[i].coin);
    if (m.size() > k) {
      bck -= *(m.begin());
      m.erase(m.begin());
    }
  }
  for (long long i = 0; i < n; i++) {
    cout << str[i] << ' ';
  }
  return 0;
}
