#include <bits/stdc++.h>
using namespace std;
bool fun(pair<long long, long long> p1, pair<long long, long long> p2) {
  return p1.second < p2.second;
}
int main() {
  int n, k;
  cin >> n >> k;
  long long arr[n];
  pair<long long, long long> b[n];
  map<long long, long long> make_pair;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    b[i].second = arr[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i].first;
  }
  sort(b, b + n, fun);
  priority_queue<pair<long long, long long>, vector<pair<long long, long long>>,
                 greater<pair<long long, long long>>>
      q;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (i <= k) {
      q.push(b[i]);
      sum += b[i].first;
      make_pair[b[i].second] = sum;
    } else {
      sum += b[i].first;
      pair<long long, long long> first = q.top();
      sum -= first.first;
      make_pair[b[i].second] = sum;
      if (first.first < b[i].first) {
        q.pop();
        q.push(b[i]);
      } else {
        sum -= b[i].first;
        sum += first.first;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    cout << make_pair[arr[i]] << " ";
  }
  return 0;
}
