#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
  long long r = 1 % P;
  for (a %= P; n; a = a * a % P, n >>= 1)
    if (n & 1) r = r * a % P;
  return r;
}
long long inv(long long x) { return x <= 1 ? 1 : inv(P % x) * (P - P / x) % P; }
const int N = 2e5 + 10;
int n, m, k;
long long sum, a[N];
struct _ {
  int p, c, id;
} q[N];
priority_queue<int, vector<int>, greater<int> > s;
int main() {
  s.push(0x7fffffff);
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i].p), q[i].id = i;
  for (int i = 1; i <= n; ++i) scanf("%d", &q[i].c);
  sort(q + 1, q + 1 + n, [](_ a, _ b) { return a.p < b.p; });
  for (int i = 1; i <= n; ++i) {
    a[q[i].id] = sum + q[i].c;
    if (s.size() <= k)
      s.push(q[i].c), sum += q[i].c;
    else if (s.top() < q[i].c) {
      sum += q[i].c - s.top();
      s.pop();
      s.push(q[i].c);
    }
  }
  for (int i = 1; i <= n; ++i) printf("%lld ", a[i]);
  putchar('\n');
}
