#include <bits/stdc++.h>
using namespace std;
const int maxn = 500010;
int n, K;
long long a[maxn], b[maxn], ans;
priority_queue<pair<long long, int>, vector<pair<long long, int> >,
               greater<pair<long long, int> > >
    q;
bool valid(long long mid) {
  long long res = 0;
  int cnt = 0;
  while (q.size()) q.pop();
  for (int i(1), i_END(n); i <= i_END; i++) {
    q.push(make_pair(a[i] + mid, 1));
    if (q.top().first + b[i] < 0) {
      res += b[i] + q.top().first;
      cnt += q.top().second;
      q.pop();
      q.push(make_pair(-b[i], 0));
    }
  }
  ans = res;
  return cnt > K;
}
namespace P1 {
bool check() {
  for (int i(1), i_END(n - 1); i <= i_END; i++)
    if (a[i] != a[i + 1]) return false;
  return true;
}
void solve() {
  sort(b + 1, b + 1 + n);
  long long res = 0;
  for (int i(1), i_END(K); i <= i_END; i++) res += b[i] + a[1];
  printf("%lld\n", res);
}
}  // namespace P1
int main() {
  long long mx = 0, l = 0, r = 0;
  scanf("%d%d", &n, &K);
  for (int i(1), i_END(n); i <= i_END; i++)
    scanf("%lld", &a[i]), mx = max(mx, a[i]);
  l -= mx;
  mx = 0;
  for (int i(1), i_END(n); i <= i_END; i++)
    scanf("%lld", &b[i]), mx = max(mx, b[i]);
  l -= mx;
  if (P1::check()) {
    P1::solve();
    return 0;
  }
  while (l < r) {
    long long mid = (l + r) >> 1;
    if (valid(mid))
      l = mid + 1;
    else
      r = mid;
  }
  valid(l);
  printf("%lld\n", ans - K * l);
  return 0;
}
