#include <bits/stdc++.h>
using namespace std;
long long n, k, ans, cntjob;
long long a[100005], b[100005], cnt[100005];
vector<pair<long long, long long> > job;
signed main() {
  cin >> n >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    if (!cnt[a[i]]) cntjob++;
    cnt[a[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> b[i];
    job.push_back({b[i], a[i]});
  }
  sort(job.begin(), job.end());
  for (long long i = 1; i <= n; i++)
    if (cnt[job[i - 1].second] > 1 && cntjob < k) {
      ans += job[i - 1].first;
      cnt[job[i - 1].second]--;
      cntjob++;
    }
  cout << ans;
}
