#include <bits/stdc++.h>
using namespace std;
const long long int N = 2e5 + 5;
void solve() {
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int>> p;
  vector<long long int> v(n);
  vector<long long int> vec(n);
  for (long long int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (long long int i = 0; i < n; i++) {
    cin >> vec[i];
    p.push_back({v[i], vec[i]});
  }
  sort(p.begin(), p.end());
  long long int sum = 0;
  map<long long int, long long int> m;
  priority_queue<long long int> pq;
  for (long long int i = 0; i < n; i++) {
    m[p[i].first] = sum + p[i].second;
    pq.push(-p[i].second);
    sum = sum + p[i].second;
    if (pq.size() > k) {
      sum = sum + pq.top();
      pq.pop();
    }
  }
  for (long long int i = 0; i < n; i++) {
    cout << m[v[i]] << " ";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
