#include <bits/stdc++.h>
using namespace std;
const int maxn = 112345;
int n, K, in[maxn], p[maxn], c[maxn];
long long res[maxn];
priority_queue<long long> que;
inline bool cmp(int a, int b) { return p[a] < p[b]; }
int main() {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]), in[i] = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  sort(in + 1, in + 1 + n, cmp);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    res[in[i]] = sum + c[in[i]];
    if ((int)que.size() < K)
      que.push(-c[in[i]]), sum += c[in[i]];
    else if (!que.empty()) {
      int v = -que.top();
      if (c[in[i]] > v) {
        sum += c[in[i]] - v;
        que.pop();
        que.push(-c[in[i]]);
      }
    }
  }
  for (int i = 1; i <= n; ++i) printf("%lld%c", res[i], i == n ? '\n' : ' ');
  return 0;
}
