#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
struct Knight {
  int ind, pow;
  long long coin;
};
Knight kn[MAX];
long long ans[MAX];
bool operator<(Knight k1, Knight k2) { return (k1.pow < k2.pow); }
vector<Knight> v;
priority_queue<long long> pq;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    ans[i] = 0LL;
    kn[i].ind = i;
    cin >> kn[i].pow;
  }
  for (int i = 1; i <= n; i++) {
    cin >> kn[i].coin;
  }
  for (int i = 1; i <= n; i++) {
    v.push_back(kn[i]);
  }
  sort(v.begin(), v.end());
  int size = 0;
  long long sum = 0LL;
  for (int i = 0; i < n; i++) {
    ans[v[i].ind] = sum + v[i].coin;
    if (size < k) {
      pq.push(-v[i].coin);
      sum += v[i].coin;
      size++;
    } else if (k > 0 && v[i].coin > -pq.top()) {
      sum += pq.top();
      pq.pop();
      pq.push(-v[i].coin);
      sum += v[i].coin;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
  return 0;
}
