#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
struct knight {
  long long p, c, ans, id;
  bool operator<(const knight &x) const { return c > x.c; }
} a[N];
long long n, k, ans[N];
bool cmp(const knight &x, const knight &y) { return x.p < y.p; }
signed main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) a[i].id = i;
  for (long long i = 1; i <= n; i++) cin >> a[i].p;
  for (long long i = 1; i <= n; i++) cin >> a[i].c;
  sort(a + 1, a + n + 1, cmp);
  priority_queue<knight> q;
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    a[i].ans = sum;
    sum += a[i].c;
    q.push(a[i]);
    if (q.size() > k) {
      sum -= q.top().c;
      q.pop();
    }
  }
  for (long long i = 1; i <= n; i++) ans[a[i].id] = a[i].ans + a[i].c;
  for (long long i = 1; i <= n; i++) cout << ans[i] << " ";
}
