#include <bits/stdc++.h>
using namespace std;
const int MAXN = 150005;
pair<pair<int, int>, int> Q[MAXN];
long long ans[MAXN];
bool cmp1(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return a.first.first < b.first.first;
}
int main() {
  int N, K;
  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &Q[i].first.first);
  }
  for (int i = 1; i <= N; i++) {
    scanf("%d", &Q[i].first.second);
    Q[i].second = i;
  }
  sort(Q + 1, Q + N + 1, cmp1);
  priority_queue<int, vector<int>, greater<int>> que;
  long long sum = 0;
  int num = 0;
  long long cur = 0;
  for (int i = 1; i <= N; i++) {
    if (Q[i].first.first == Q[i - 1].first.first) {
      ans[Q[i].second] = cur + Q[i].first.second;
    } else {
      ans[Q[i].second] = sum + Q[i].first.second;
      cur = sum;
    }
    if (K != 0) {
      if (num == K) {
        if (Q[i].first.second > que.top()) {
          sum -= que.top();
          sum += Q[i].first.second;
          que.pop();
          que.push(Q[i].first.second);
        }
      } else {
        num++;
        sum += Q[i].first.second;
        que.push(Q[i].first.second);
      }
    }
  }
  for (int i = 1; i <= N; i++) cout << ans[i] << " ";
  return 0;
}
