#include <bits/stdc++.h>
using namespace std;
bool comparator(pair<long long int, long long int> a,
                pair<long long int, long long int> b) {
  if (a.first <= b.first) return true;
  return false;
}
int main() {
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int> > V(n);
  vector<long long int> vec(n);
  for (long long int i = 0; i < n; i++) {
    cin >> V[i].first;
    vec[i] = V[i].first;
  }
  for (long long int i = 0; i < n; i++) {
    cin >> V[i].second;
  }
  sort(V.begin(), V.end(), comparator);
  long long int total = 0;
  priority_queue<int, vector<int>, greater<int> > pq;
  for (long long int i = 0; i < n; i++) {
    if (i < k) {
      total = total + V[i].second;
      pq.push(V[i].second);
      V[i].second = total;
    } else {
      long long int current = total + V[i].second;
      if (k >= 1) {
        if (V[i].second > pq.top()) {
          total = total - pq.top();
          total = total + V[i].second;
          pq.pop();
          pq.push(V[i].second);
        }
      }
      V[i].second = current;
    }
  }
  map<long long int, long long int> M;
  for (long long int i = 0; i < n; i++) {
    M[V[i].first] = V[i].second;
  }
  for (int i = 0; i < n; i++) {
    cout << M[vec[i]] << " ";
  }
  cout << endl;
  return 0;
}
