#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5, MOD = 1e9 + 7;
bool c[11];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long ans[n];
  pair<int, pair<int, int>> a[n];
  priority_queue<int> pq;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].first);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].second.first);
    a[i].second.second = i;
    ans[i] = a[i].second.first;
  }
  if (!k) {
    for (int i = 0; i < n; i++) {
      printf("%lld ", ans[i]);
    }
    return 0;
  }
  sort(a, a + n);
  long long sum = a[0].second.first;
  pq.push(-a[0].second.first);
  for (int i = 1; i < n; i++) {
    ans[a[i].second.second] += sum;
    if (pq.size() == k) {
      if (abs(pq.top()) < a[i].second.first) {
        sum -= (abs(pq.top()));
        pq.pop();
        pq.push(-a[i].second.first);
        sum += a[i].second.first;
      }
    } else {
      pq.push(-a[i].second.first);
      sum += a[i].second.first;
    }
  }
  for (int i = 0; i < n; i++) {
    printf("%lld ", ans[i]);
  }
  return 0;
}
