#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")
using namespace std;
const int N = (int)5e5 + 7, MOD = (int)1e9 + 7;
int n, k;
pair<pair<int, int>, int> a[N];
map<int, long long> mp;
long long cnt;
deque<int> v;
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return a.second < b.second;
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first.first;
    a[i].second = i;
  }
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first.second;
  }
  sort(a + 1, a + n + 1);
  for (int i = 1; i <= n; i++) {
    mp[a[i].first.first] = cnt + a[i].first.second;
    if ((int)v.size() < k) {
      v.push_back(a[i].first.second);
      cnt += a[i].first.second;
      continue;
    }
    sort(v.begin(), v.end());
    if (v[0] < a[i].first.second) {
      v.push_back(a[i].first.second);
      sort(v.begin(), v.end());
      v.erase(v.begin());
      cnt = 0;
      for (int j = 0; j < (int)v.size(); j++) {
        cnt += v[j];
      }
    }
  }
  sort(a + 1, a + n + 1, cmp);
  for (int i = 1; i <= n; i++) {
    cout << mp[a[i].first.first] << ' ';
  }
  exit(0);
}
