#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int a[205];
struct Node {
  int p, c, opt;
  bool operator<(const Node &a) const { return p < a.p; }
} s[100050];
priority_queue<int, vector<int>, greater<int> > q;
long long ans[100050];
int main() {
  int n = read(), m = read();
  for (int i = 1; i <= n; i++) s[i].p = read(), s[i].opt = i;
  for (int i = 1; i <= n; i++) s[i].c = read();
  sort(s + 1, s + n + 1);
  int cnt = 0;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (cnt < m) {
      q.push(s[i].c);
      cnt++;
      sum += s[i].c;
      ans[s[i].opt] = sum;
    } else {
      ans[s[i].opt] = sum + s[i].c;
      if (!q.empty() && s[i].c > q.top()) {
        sum += s[i].c - q.top();
        q.pop();
        q.push(s[i].c);
      }
    }
  }
  for (int i = 1; i <= n; i++) printf("%I64d ", ans[i]);
}
