#include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("-ffloat-store")
using namespace std;
const long long Mod = 1e9 + 7;
const long long Inf = 1e18;
const long long Lim = 1e5 + 1e3;
const double eps = 1e-10;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long int n, k;
  cin >> n >> k;
  long long int a[n], b[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (long long int i = 0; i < n; i++) {
    cin >> b[i];
  }
  map<long long int, vector<long long int> > c;
  for (long long int i = 0; i < n; i++) {
    c[a[i]].push_back(b[i]);
  }
  vector<long long int> need;
  long long int good = 0;
  long long int Ans = 0;
  for (auto to : c) {
    auto a = to.second;
    sort(a.begin(), a.end());
    good += (a.size() > 0);
    for (long long int i = 0; i < a.size() - 1; i++) {
      need.push_back(a[i]);
    }
  }
  sort(need.begin(), need.end());
  long long int now = 0;
  for (long long int i = good; i < k; i++) {
    Ans += need[now++];
  }
  cout << Ans << "\n";
  return 0;
}
