#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1E5 + 7;
ll ans[N];
struct node {
  int p, c;
  int id;
  node() {}
  bool operator<(const node &k) const { return p < k.p; }
};
node a[N];
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i].p;
    a[i].id = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i].c;
  }
  sort(a, a + n);
  ll num = 0;
  multiset<int> jud;
  for (int i = 0; i < n; i++) {
    ans[a[i].id] = a[i].c + num;
    if (jud.size() < k) {
      jud.insert(a[i].c);
      num += a[i].c;
    } else if (k && *jud.begin() < a[i].c) {
      num = num - *jud.begin() + a[i].c;
      jud.erase(jud.begin());
      jud.insert(a[i].c);
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
