#include <bits/stdc++.h>
struct knight {
  size_t id;
  int64_t p, c;
};
bool operator<(const knight& lhs, const knight& rhs) { return lhs.p < rhs.p; }
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  size_t n, k;
  std::cin >> n >> k;
  std::vector<knight> knights(n);
  for (size_t i = 0; i < n; ++i) {
    knights[i].id = i;
    std::cin >> knights[i].p;
  }
  for (size_t i = 0; i < n; ++i) {
    std::cin >> knights[i].c;
  }
  sort(knights.begin(), knights.end());
  std::priority_queue<int64_t, std::vector<int64_t>, std::greater<int64_t>> pq;
  std::vector<int64_t> result(n);
  size_t ptr = 0;
  int64_t sum = 0;
  for (size_t i = 0; i < n; ++i) {
    while (knights[ptr].p < knights[i].p) {
      pq.push(knights[ptr].c);
      sum += knights[ptr].c;
      ptr += 1;
      if (pq.size() > k) {
        sum -= pq.top();
        pq.pop();
      }
    }
    result[knights[i].id] = sum + knights[i].c;
  }
  for (int64_t u : result) {
    std::cout << u << ' ';
  }
  std::cout << '\n';
}
