#include <bits/stdc++.h>
using namespace std;
long long int dx[] = {1, -1, 0, 0};
long long int dy[] = {0, 0, -1, 1};
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  return a.first < b.first;
}
long long int power(long long int a, long long int n) {
  long long int res = 1;
  while (n > 0) {
    if (n & 1)
      res = ((res % 1000000007) * (a % 1000000007)) % 1000000007, n--;
    else
      a = ((a % 1000000007) * (a % 1000000007)) % 1000000007, n /= 2;
  }
  return res;
}
long long int nCr(long long int n, long long int r) {
  if (r > n) return 0;
  double res = 1;
  for (long long int i = 1; i <= r; i++) res = (res * (n - r + i)) / i;
  return (long long int)(res + 0.01);
}
long long int powe(long long int a, long long int n) {
  long long int res = 1;
  for (long long int i = 0; i < n; i++) res *= a;
  return res;
}
void solve() {
  long long int n, k;
  cin >> n >> k;
  long long int p[n], c[n];
  long long int ans[n];
  vector<pair<long long int, long long int>> vp;
  map<long long int, long long int> mp;
  for (long long int i = 0; i < n; i++) cin >> p[i], mp[p[i]] = i;
  for (long long int i = 0; i < n; i++) cin >> c[i];
  for (long long int i = 0; i < n; i++) {
    vp.push_back({p[i], c[i]});
    ans[i] = c[i];
  }
  sort(vp.begin(), vp.end(), cmp);
  priority_queue<long long int, vector<long long int>, greater<long long int>>
      pq;
  long long int mi = 100000000000000000;
  for (long long int i = 0; i < n; i++) {
    if (i < k) {
      long long int tp = mp[vp[i].first];
      priority_queue<long long int, vector<long long int>,
                     greater<long long int>>
          temp;
      temp = pq;
      while (!temp.empty()) {
        ans[tp] += temp.top();
        temp.pop();
      }
      pq.push(vp[i].second);
      mi = min(mi, vp[i].second);
    } else {
      long long int tp = mp[vp[i].first];
      priority_queue<long long int, vector<long long int>,
                     greater<long long int>>
          temp;
      temp = pq;
      while (!temp.empty()) {
        ans[tp] += temp.top();
        temp.pop();
      }
      if (vp[i].second > mi) {
        pq.pop();
        pq.push(vp[i].second);
        mi = pq.top();
      }
    }
  }
  for (long long int i = 0; i < n; i++) cout << ans[i] << " ";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    solve();
  }
}
