#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, i;
  cin >> n >> k;
  vector<pair<long long, long long>> v;
  vector<long long> inp, p;
  vector<long long>::iterator it;
  map<long long, long long> m;
  for (i = 0; i < n; i++) {
    long long x;
    cin >> x;
    v.push_back(make_pair(x, 0));
    inp.push_back(x);
  }
  for (i = 0; i < n; i++) cin >> v[i].second;
  sort(v.begin(), v.end());
  int t = 0, u = 0;
  long long sum = 0;
  for (i = 0; i < n; i++) {
    if (t < k) {
      for (it = p.begin(); it != p.end(); it++) {
        if (v[i].second >= *it) {
          p.insert(it, v[i].second);
          t++;
          break;
        }
      }
      if (it == p.end()) {
        p.push_back(v[i].second);
        t++;
      }
      sum += v[i].second;
      m[v[i].first] = sum;
    } else {
      if (u == 1) {
        for (it = p.begin(); it != p.end(); it++) {
          if (v[i - 1].second >= *it) {
            p.insert(it, v[i - 1].second);
            sum += v[i - 1].second;
            sum -= p.back();
            p.pop_back();
            break;
          }
        }
      }
      m[v[i].first] = sum + v[i].second;
      if (u == 0) u = 1;
    }
  }
  for (i = 0; i < n; i++) {
    cout << m[inp[i]] << ' ';
  }
  return 0;
}
