#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int expo(long long int x, long long int y) {
  long long int res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
void matmul(long long int a[][2], long long int b[][2]) {
  long long int tmp[2][2];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      tmp[i][j] = 0;
      for (int k = 0; k < 2; k++)
        tmp[i][j] = (tmp[i][j] + a[i][k] * b[k][j]) % mod;
    }
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 2; j++) a[i][j] = tmp[i][j];
}
long long int fibo(int n) {
  if (n == 0)
    return 0;
  else if (n == 1)
    return 1;
  long long int T[2][2] = {{0, 1}, {1, 1}};
  long long int res[2][2] = {{1, 0}, {0, 1}};
  n--;
  while (n) {
    if (n & 1) matmul(res, T);
    n >>= 1;
    matmul(T, T);
  }
  return res[1][1];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k;
  cin >> n >> k;
  int p[n];
  long long int c[n];
  for (int i = 0; i < n; i++) cin >> p[i];
  for (int i = 0; i < n; i++) cin >> c[i];
  vector<pair<int, int> > v;
  for (int i = 0; i < n; i++) {
    v.emplace_back(p[i], i);
  }
  sort(v.begin(), v.end());
  long long int sum = 0, ans[n];
  priority_queue<long long> pq;
  for (int i = 0; i < n; i++) {
    if (pq.size() <= k) {
      sum += c[v[i].second];
      pq.push(c[v[i].second]);
      ans[v[i].second] = sum;
    } else {
      sum = c[v[i].second];
      vector<int> req(k);
      for (int i = 0; i < k; i++) {
        int tmp = pq.top();
        sum += tmp;
        pq.pop();
        req[i] = tmp;
      }
      ans[v[i].second] = sum;
      pq = priority_queue<long long int>();
      for (int i = 0; i < k; i++) pq.push(req[i]);
      pq.push(c[v[i].second]);
    }
  }
  for (int i = 0; i < n; i++) cout << ans[i] << " ";
  return 0;
}
