#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, k;
  cin >> n >> k;
  long long int Y[n];
  long long int x, y;
  vector<pair<long long int, pair<long long int, long long int> > > X(n);
  for (int i = 0; i < n; ++i) {
    cin >> x;
    X[i].first = x;
  }
  for (int i = 0; i < n; ++i) {
    cin >> x;
    X[i].second.first = x;
    X[i].second.second = i;
  }
  sort(X.begin(), X.end());
  priority_queue<long long int, vector<long long int>, greater<long long int> >
      A;
  long long int sum = 0;
  for (int i = 0; i < X.size(); ++i) {
    if (A.size() > k) {
      sum -= A.top();
      A.pop();
    }
    A.push(X[i].second.first);
    sum += X[i].second.first;
    Y[X[i].second.second] = sum;
  }
  for (int i = 0; i < n; ++i) {
    cout << Y[i] << " ";
  }
  cout << endl;
  return 0;
}
