#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long power[n];
  long long coin[n];
  pair<pair<int, int>, int> arr[n];
  for (int i = 1; i <= n; i++) {
    cin >> power[i];
    arr[i].first.first = power[i];
    arr[i].second = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> coin[i];
    arr[i].first.second = coin[i];
  }
  sort(arr + 1, arr + n + 1);
  priority_queue<int> max_heap;
  long long output[n + 2];
  memset(output, -1, sizeof(output));
  long long lastadded = 0;
  for (int i = 1; i <= n; i++) {
    while (true) {
      if (lastadded + 1 == i) {
        break;
      }
      lastadded++;
      max_heap.push(arr[lastadded].first.second);
    }
    vector<long long> temp;
    long long cnt = 1;
    long long sum = arr[i].first.second;
    while (max_heap.size() != 0 && cnt <= k) {
      sum += max_heap.top();
      temp.push_back(max_heap.top());
      max_heap.pop();
      ++cnt;
    }
    for (int i = 0; i < temp.size(); i++) {
      max_heap.push(temp[i]);
    }
    output[arr[i].second] = sum;
  }
  for (int i = 1; i <= n; i++) {
    if (output[i] != -1) {
      cout << output[i] << " ";
    }
  }
}
