#include <bits/stdc++.h>
using namespace std;
long long int cost[10];
long long int ans[100000];
long long int p[100000], c[100000];
bool cmp(pair<long long int, long long int> a,
         pair<long long int, long long int> b) {
  return (p[a.first] < p[b.first]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  vector<pair<long long int, long long int>> v;
  for (long long int i = 0; i < n; i++) cin >> p[i];
  for (long long int i = 0; i < n; i++) cin >> c[i];
  for (long long int i = 0; i < n; i++) {
    v.push_back({i, c[i]});
  }
  sort(v.begin(), v.end(), cmp);
  long long int sum = 0;
  for (long long int i = 0; i < k; i++) cost[i] = 0;
  for (long long int i = 0; i < n; i++) {
    long long int ind = v[i].first, cn = v[i].second;
    ans[ind] = sum + cn;
    if (k > 0 and cn > cost[0]) sum += (cn - cost[0]);
    long long int pos = k;
    for (long long int j = 0; j < k; j++) {
      if (cost[j] >= cn) {
        pos = j;
        break;
      }
    }
    for (long long int h = 0; h < pos - 1; h++) cost[h] = cost[h + 1];
    if (pos > 0) cost[pos - 1] = cn;
  }
  for (long long int i = 0; i < n; i++) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
