#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = (int)(1e9 + 7)) {
  return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = (int)(1e9 + 7)) {
  return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = (int)(1e9 + 7)) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
long long inv(long long a, long long p = (int)(1e9 + 7)) {
  return fpow(a, p - 2, p);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long n, k;
  cin >> n >> k;
  long long a[n], b[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  vector<pair<long long, long long>> v;
  map<long long, long long> make_pair, mp1;
  for (int i = 0; i < n; i++) {
    make_pair[a[i]] = b[i];
    v.push_back({a[i], b[i]});
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  priority_queue<long long, vector<long long>, greater<long long>> pq;
  if (k == 0) {
    for (int i = 0; i < n; i++) cout << b[i] << " ";
    return 0;
  }
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    mp1[v[i].first] = v[i].second + sum;
    if (cnt < k) {
      pq.push(v[i].second);
      cnt++;
      sum += v[i].second;
    } else {
      long long t = pq.top();
      if (t < v[i].second) {
        sum -= t;
        pq.pop();
        sum += v[i].second;
        pq.push(v[i].second);
      }
    }
  }
  for (int i = 0; i < n; i++) cout << mp1[a[i]] << " ";
}
