#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, a[100000], ans = 0;
  cin >> n >> k;
  vector<pair<int, int>> A(n);
  map<int, long long> B;
  priority_queue<int> C;
  for (int i = 0; i < n; i++) cin >> a[i], A[i].first = a[i];
  for (int i = 0; i < n; i++) cin >> A[i].second;
  sort(A.begin(), A.end());
  for (int i = 0; i < n; i++) {
    C.push(-A[i].second);
    ans += A[i].second;
    B[A[i].first] = ans;
    if (C.size() > k) {
      ans += C.top();
      C.pop();
    }
  }
  for (int i = 0; i < n; i++) cout << B[a[i]] << ' ';
  return 0;
}
