#include <bits/stdc++.h>
using namespace std;
void stop() {}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
int main() {
  fast();
  int n, m;
  cin >> n >> m;
  long long f[100005] = {0};
  vector<vector<long long> > a(n, vector<long long>(4));
  for (int i = 0; i < n; i++) {
    cin >> a[i][0];
    a[i][2] = i;
  }
  for (int i = 0; i < n; i++) {
    cin >> a[i][1];
    a[i][3] = a[i][1];
  }
  sort(a.begin(), a.end());
  priority_queue<int> pr;
  pr.push(a[0][1]);
  for (int i = 1; i < n; i++) {
    long long sum = 0;
    int j = 0;
    queue<int> q;
    while (pr.size() && j++ < m) {
      sum += pr.top();
      q.push(pr.top());
      pr.pop();
    }
    pr.push(a[i][1]);
    while (q.size()) {
      pr.push(q.front());
      q.pop();
    }
    a[i][3] += sum;
  }
  for (int i = 0; i < n; i++) f[a[i][2]] = a[i][3];
  for (int i = 0; i < n; i++) cout << f[i] << " ";
  stop();
  return 0;
}
