#include <bits/stdc++.h>
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
using namespace std;
int n, k;
long long ans[maxn];
struct node {
  int x, y;
} a[maxn];
map<int, int> mp;
priority_queue<int, vector<int>, greater<int> > q;
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i].x);
    mp[a[i].x] = i;
  }
  for (int i = 0; i < n; i++) scanf("%d", &a[i].y);
  sort(a, a + n, cmp);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    if (q.size() > k) {
      sum -= q.top();
      q.pop();
    }
    sum += a[i].y;
    q.push(a[i].y);
    ans[mp[a[i].x]] = sum;
  }
  for (int i = 0; i < n; i++) printf("%lld ", ans[i]);
  return 0;
}
