#include <bits/stdc++.h>
using namespace std;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.first != b.first)
    return a.first > b.first;
  else
    return a.second > b.second;
}
long long pow(long long base, long long x) {
  long long ans = 1;
  for (long long i = 1; i <= x; i++) ans *= base;
  return ans;
}
void debug(string s) { cout << s << "\n"; }
long long ar[1000005], br[1000005], cr[1000005], dr[1000005], ans[1000005];
int main() {
  long long n, k;
  cin >> n >> k;
  map<long long, long long> mp;
  vector<pair<long long, long long>> v;
  for (long long i = 1; i <= n; i++) {
    cin >> ar[i];
    mp[ar[i]] = i;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> br[i];
    v.push_back({ar[i], br[i]});
  }
  sort(v.begin(), v.end());
  for (long long i = 0; i < n; i++) {
    cr[i + 1] = v[i].first;
    dr[i + 1] = v[i].second;
  }
  long long sum = 0;
  multiset<long long> st;
  for (long long i = 1; i <= n; i++) {
    long long s = sum + dr[i];
    st.insert(dr[i]);
    sum += dr[i];
    if ((long long)st.size() == k + 1) {
      auto it = st.begin();
      sum -= *it;
      st.erase(st.lower_bound(*it));
    }
    long long index = mp[cr[i]];
    ans[index] = s;
  }
  for (long long i = 1; i <= n; i++) cout << ans[i] << ' ';
  cout << "\n";
  return 0;
}
