#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, k;
  cin >> n >> k;
  vector<pair<long long, pair<long long, long long>>> v(n);
  for (long long i = 0; i < n; i++) {
    long long u;
    cin >> u;
    v[i].first = u;
    v[i].second.first = i;
  }
  for (long long i = 0; i < n; i++) {
    long long u;
    cin >> u;
    v[i].second.second = u;
  }
  sort(v.begin(), v.end());
  long long ans = 0;
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  long long curr = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    mp[v[i].second.first] = curr + v[i].second.second;
    if (k == 0)
      continue;
    else {
      if (pq.size() < k) {
        pq.push(v[i].second.second);
        curr = curr + v[i].second.second;
      } else {
        long long topp = pq.top();
        if (topp < v[i].second.second) {
          pq.pop();
          pq.push(v[i].second.second);
          curr = curr - topp + v[i].second.second;
        }
      }
    }
  }
  for (auto x : mp) cout << x.second << " ";
}
