#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, long long> > v(n);
  vector<long long> a(n);
  long long i;
  for (i = 0; i < n; i++) {
    cin >> v[i].first;
    a[i] = v[i].first;
  }
  for (i = 0; i < n; i++) {
    cin >> v[i].second;
  }
  sort(v.begin(), v.end());
  long long s = 0;
  long long c = 0;
  long long min_ele = INT_MAX, max_ele = INT_MIN;
  map<long long, long long> mp;
  priority_queue<long long, vector<long long>, greater<long long> > pq;
  for (i = 0; i < n; i++) {
    if (c <= k) {
      s += v[i].second;
      min_ele = min(min_ele, v[i].second);
      max_ele = max(max_ele, v[i].second);
      pq.push(v[i].second);
      mp[v[i].first] = s;
      c++;
    } else {
      long long p = pq.top();
      pq.pop();
      s -= p;
      s += v[i].second;
      pq.push(v[i].second);
      min_ele = pq.top();
      max_ele = max(max_ele, a[i]);
      mp[v[i].first] = s;
    }
  }
  for (i = 0; i < n; i++) {
    cout << mp[a[i]] << " ";
  }
  cout << endl;
  return 0;
}
