#include <bits/stdc++.h>
using namespace std;
int n, k;
multiset<long long> s;
map<long long, int> m;
pair<long long, long long> arr[100009];
long long output[100009];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &arr[i].first);
    m[arr[i].first] = i + 1;
  }
  for (int i = 0; i < n; i++) scanf("%lld", &arr[i].second);
  sort(arr, arr + n);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    output[m[arr[i].first] - 1] = ans + arr[i].second;
    if (s.size() < k) {
      s.insert(arr[i].second);
      ans += arr[i].second;
    } else if (s.size() > 0) {
      int aa = *s.begin();
      if (aa < arr[i].second) {
        ans -= aa;
        ans += arr[i].second;
        s.erase(s.find(aa));
        s.insert(arr[i].second);
      }
    }
  }
  for (int i = 0; i < n; i++) printf("%lld ", output[i]);
  printf("\n");
  return 0;
}
