#include <bits/stdc++.h>
using namespace std;
const int nmax = 100000 + 7;
int n, k;
struct data {
  long long a, b;
};
data s[nmax], jnd[nmax];
int jobsnotdone = 0;
int jobsdone[nmax];
int coun = 0;
int p = 0;
void input() {
  cin >> n >> k;
  memset(jobsdone, 0, sizeof(jobsdone));
  for (int i = 1; i <= n; ++i) {
    cin >> s[i].a;
  }
  for (int i = 1; i <= n; ++i) {
    cin >> s[i].b;
  }
}
bool compare(data a, data b) { return a.b < b.b; }
bool cmp(data a, data b) { return a.a < b.a || a.a == b.a && a.b > b.b; }
void solve() {
  sort(s + 1, s + n + 1, cmp);
  for (int i = 1; i <= n; ++i) {
    if (jobsdone[s[i].a] == 0) {
      ++coun;
      jobsdone[s[i].a] = i;
    } else {
      ++p;
      jnd[p].a = i;
    }
  }
  for (int i = 1; i <= p; ++i) {
    jnd[i].b = s[jnd[i].a].b;
  }
  long long res = 0;
  sort(jnd + 1, jnd + p + 1, compare);
  for (int i = 1; i <= max(0, k - coun); ++i) {
    res += jnd[i].b;
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  input();
  solve();
  return 0;
}
