#include <bits/stdc++.h>
const int N = 1e5 + 5;
int t[N], a[N], b[N];
using namespace std;
int main() {
  int n, k, x, c = 0;
  long long sum = 0;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    if (x > t[a[i]]) std::swap(x, t[a[i]]);
    if (x) b[++c] = x;
  }
  std::nth_element(b + 1, b - n + k + c, b + 1 + c);
  for (int i = 1; i <= c - n + k; ++i) sum += b[i];
  printf("%lld", sum);
  return 0;
}
