#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, k;
  cin >> n >> k;
  vector<long long> p(n), m(n);
  vector<pair<pair<long long, long long>, long long> > knights;
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> m[i];
  }
  for (long long i = 0; i < n; i++) {
    knights.push_back(make_pair(make_pair(p[i], m[i]), i));
  }
  vector<long long> results(n);
  sort(knights.begin(), knights.end());
  priority_queue<long long> pq;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    results[knights[i].second] = sum + knights[i].first.second;
    if (i < k) {
      sum += knights[i].first.second;
      pq.push(-knights[i].first.second);
    } else if (k != 0 && -pq.top() < knights[i].first.second) {
      sum -= -pq.top();
      pq.pop();
      sum += knights[i].first.second;
      pq.push(-knights[i].first.second);
    }
  }
  for (long long i : results) {
    cout << i << " ";
  }
  return 0;
}
