#include <bits/stdc++.h>
using namespace std;
const long long N = (long long)1e6 + 10;
long long v[N];
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<pair<int, int>, int>> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i].first.first, a[i].second = i;
  for (int i = 0; i < n; ++i) cin >> a[i].first.second;
  sort(a.begin(), a.end());
  long long sum = 0;
  multiset<long long> st;
  for (int i = 0; i < n; ++i) {
    v[a[i].second] = sum + a[i].first.second;
    if (st.size() < m) {
      st.insert(a[i].first.second);
      sum += a[i].first.second;
    } else {
      st.insert(a[i].first.second);
      sum -= (*st.begin());
      sum += a[i].first.second;
      st.erase(st.begin());
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << v[i] << " ";
  }
  cout << endl;
}
