#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, k, temp1, temp2;
  cin >> n >> k;
  long long int p[n], c[n];
  vector<pair<pair<long long int, long long int>, long long int>> v;
  for (long long int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (long long int i = 0; i < n; i++) {
    cin >> c[i];
  }
  for (long long int i = 0; i < n; i++) {
    v.push_back(make_pair(make_pair(p[i], i), c[i]));
  }
  sort(v.begin(), v.end());
  multiset<long long int> m;
  long long int sum = 0;
  long long int i = 0;
  for (; i <= k && i < n; i++) {
    sum += v[i].second;
    m.insert(v[i].second);
    c[v[i].first.second] = sum;
  }
  for (; i < n; i++) {
    sum = sum - *m.cbegin() + v[i].second;
    m.erase(m.cbegin());
    m.insert(v[i].second);
    c[v[i].first.second] = sum;
  }
  for (long long int i = 0; i < n; i++) {
    cout << c[i] << " ";
  }
  return 0;
}
