#include <bits/stdc++.h>
using namespace std;
struct knight {
  long long int p, c, id, a;
};
bool func(knight k1, knight k2) { return k1.p < k2.p; }
int main() {
  int n, m;
  cin >> n >> m;
  knight k[n];
  for (int i = 0; i < n; i++) cin >> k[i].p;
  for (int i = 0; i < n; i++) cin >> k[i].c;
  for (int i = 0; i < n; i++) k[i].id = i;
  sort(k, k + n, func);
  vector<long long int> v;
  v.push_back(k[0].c);
  k[0].a = k[0].c;
  for (int i = 1; i < n; i++) {
    k[i].a = k[i].c;
    int l = min(i, m);
    for (int j = 0; j < l; j++) k[i].a += v[j];
    if (l < m)
      v.push_back(k[i].c);
    else {
      sort(v.begin(), v.end());
      v[0] = max(v[0], k[i].c);
    }
  }
  long long int ans[n];
  for (int i = 0; i < n; i++) ans[k[i].id] = k[i].a;
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
