#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int MAXN = int(5e6) + 256, MXN = int(1e6);
const int MOD = int(1e9) + 7;
inline int nextInt() {
  int s = 1, x = 0, c = getc(stdin);
  while (c <= 32) c = getc(stdin);
  if (c == '-') s = -1, c = getc(stdin);
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin);
  return x * s;
}
template <typename T>
inline T gcd(T a, T b) {
  while (a && b) a > b ? a %= b : b %= a;
  return a + b;
}
inline bool Palindrome(const string& s) {
  return equal(s.begin(), s.end(), s.rbegin());
}
long long p[MAXN], c[MAXN], res[MAXN];
int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    p[i] = nextInt();
  }
  for (int i = 0; i < n; ++i) {
    c[i] = nextInt();
  }
  vector<pair<long long, long long> > v;
  for (int i = 0; i < n; ++i) {
    v.push_back({p[i], i});
  }
  sort(v.begin(), v.end());
  multiset<long long> S;
  long long cur = 0;
  for (int i = 0; i < n; ++i) {
    res[v[i].second] = cur;
    S.insert(c[v[i].second]);
    cur += c[v[i].second];
    if (S.size() > k) {
      cur -= *S.begin();
      S.erase(S.begin());
    }
  }
  for (int i = 0; i < n; ++i) {
    printf("%lld ", res[i] + c[i]);
  }
  return 0;
}
