#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  vector<pair<int, int>> e;
  for (int i = 0; i < n; i++) e.push_back({p[i], i});
  sort(begin(e), end(e));
  vector<long long> res(n);
  long long cur = 0;
  multiset<int> s;
  for (int i = 0; i < n; i++) {
    if (s.size() >= k + 1) {
      auto val = *s.begin();
      cur -= val;
      s.erase(s.lower_bound(val));
    }
    s.insert(c[e[i].second]);
    cur += c[e[i].second];
    res[e[i].second] = cur;
  }
  for (int i = 0; i < n; i++) cout << res[i] << " \n"[i == n - 1];
  return 0;
}
