#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
int n, k, a[N], b[N];
long long l = 0, r = 2e9, ans;
priority_queue<int, vector<int>, greater<int> > q1;
priority_queue<int> q2;
inline int read() {
  char c = getchar();
  int ans = 0;
  while (c < 48 || c > 57) c = getchar();
  while (c >= 48 && c <= 57)
    ans = (ans << 3) + (ans << 1) + (c ^ 48), c = getchar();
  return ans;
}
int main() {
  n = read(), k = read();
  for (register int i = 1; i <= n; ++i) a[i] = -read();
  for (register int i = 1; i <= n; ++i) b[i] = -read();
  while (l <= r) {
    int cnt = 0;
    long long mid = l + r >> 1, s = 0;
    while (!q1.empty()) q1.pop();
    while (!q2.empty()) q2.pop();
    for (register int i = n; i; --i) {
      q1.push(a[i]), q2.push(b[i]);
      long long s1 = a[i] - q1.top(), s2 = a[i] + q2.top() + mid;
      if (s2 >= s1)
        s += s2, ++cnt, q2.pop();
      else
        s += s1, q1.pop();
    }
    if (cnt <= k)
      ans = s - mid * k, l = mid + 1;
    else
      r = mid - 1;
  }
  printf("%lld", -ans);
  return 0;
}
