#include <bits/stdc++.h>
using namespace std;
const long long infl = 1e18 + 5;
long long n, m, k, q, x, y, f, val, t, i, j;
long long ind, cnt, sz, sm, ans, mx, mn;
long long a[1000004], b[1000004], c[1000004];
vector<pair<long long, long long> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  if (fopen("inp.txt", "r")) {
    freopen("myfile.txt", "w", stdout);
    freopen("inp.txt", "r", stdin);
  }
  cin >> n >> k;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    v.emplace_back(a[i], i);
  }
  for (i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(v.begin(), v.end());
  multiset<long long> s, second;
  x = 0;
  for (i = 0; i < v.size(); i++) {
    m = k;
    ind = v[i].second;
    x = c[ind];
    while (m--) {
      if (!s.empty()) {
        sm = *s.begin();
        x -= sm;
        s.erase(s.find(sm));
        second.insert(sm);
      }
    }
    s.insert(-1 * c[ind]);
    while (!second.empty()) {
      sm = *second.begin();
      s.insert(sm);
      second.erase(second.find(sm));
    }
    b[ind] = x;
  }
  for (i = 0; i < n; i++) cout << b[i] << " ";
  return 0;
}
