#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i, a, x, ans[100001], c[100001], sum;
  vector<pair<int, int> > v;
  set<pair<int, int> > second;
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a;
    v.push_back({a, i});
  }
  sort(v.begin(), v.end());
  for (i = 0; i < n; i++) cin >> c[i];
  for (i = 0; i < n; i++) {
    x = v[i].second;
    ans[x] = c[x] + sum;
    sum += c[x];
    second.insert({c[x], x});
    if (second.size() > k) {
      sum -= (*second.begin()).first;
      second.erase((*second.begin()));
    }
  }
  for (i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
