#include <bits/stdc++.h>
using namespace std;
long long a[100005];
long long n, k;
struct ed {
  long long num, t, jb;
};
long long cmp(struct ed a1, struct ed b1) { return a1.t < b1.t; }
long long j[100005];
struct ed b[100005];
int main() {
  cin >> n >> k;
  memset(j, 0, sizeof(j));
  long long all = 0;
  for (long long i = 1; i <= n; i++) {
    cin >> b[i].jb;
    if (j[b[i].jb] == 0) all++;
    j[b[i].jb]++;
  }
  all = k - all;
  for (long long i = 1; i <= n; i++) {
    b[i].num = i;
    cin >> b[i].t;
  }
  sort(b, b + n + 1, cmp);
  long long ans = 0;
  long long opt = 0;
  for (long long i = 1; i <= n; i++) {
    if (j[b[i].jb] <= 1) continue;
    if (opt == all) break;
    ans += b[i].t;
    j[b[i].jb]--;
    opt++;
  }
  cout << ans << endl;
}
