#include <bits/stdc++.h>
using namespace std;
long long int n, k, A[100010], x;
vector<pair<long long int, long long int> > v, in;
int main() {
  cin >> n >> k;
  for (long long int i = 1; i <= n; i++) {
    cin >> A[i];
    in.push_back(make_pair(A[i], i - 1));
  }
  for (long long int i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(make_pair(A[i], x));
  }
  sort(v.begin(), v.end());
  sort(in.begin(), in.end());
  long long int sum = 0;
  priority_queue<long long int, vector<long long int>, greater<long long int> >
      pq;
  vector<long long int> ans;
  for (long long int i = 0; i < v.size(); i++) {
    if (i < k) {
      sum += v[i].second;
      pq.push(v[i].second);
      ans.push_back(sum);
    } else if (i == k) {
      ans.push_back(sum + v[i].second);
    } else {
      if (pq.empty()) {
        ans.push_back(sum + v[i].second);
      } else {
        if (v[i - 1].second > pq.top()) {
          sum = sum - pq.top() + v[i - 1].second;
          pq.pop();
          pq.push(v[i - 1].second);
          ans.push_back(sum + v[i].second);
        } else {
          ans.push_back(sum + v[i].second);
        }
      }
    }
  }
  for (long long int i = 0; i < ans.size(); i++) {
    cout << ans[in[i].second] << " ";
  }
  return 0;
}
