#include <bits/stdc++.h>
using namespace std;
const int maxn = 500005;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x;
}
int n, k, cnt;
long long sum, a[maxn], b[maxn];
priority_queue<int, vector<int>, greater<int> > A, B;
bool pd(long long v) {
  while (!A.empty()) A.pop();
  while (!B.empty()) B.pop();
  cnt = 0;
  sum = 0;
  B.push(0x3f3f3f3f);
  for (int i = 1; i <= n; ++i) a[i] -= v, b[i] -= v;
  for (int i = 1; i <= n; ++i) {
    A.push(a[i]);
    int ta = A.top(), tb = B.top();
    if (b[i] + ta < 0 && b[i] + tb < 0) {
      if (ta < tb) {
        ++cnt;
        A.pop();
        sum += ta + b[i];
        B.push(-b[i]);
      } else {
        sum += tb + b[i];
        B.pop();
        B.push(-b[i]);
      }
    } else if (b[i] + ta < 0) {
      ++cnt;
      A.pop();
      sum += ta + b[i];
      B.push(-b[i]);
    } else if (b[i] + tb < 0) {
      sum += tb + b[i];
      B.pop();
      B.push(-b[i]);
    }
  }
  for (int i = 1; i <= n; ++i) a[i] += v, b[i] += v;
  return cnt <= k;
}
int main() {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= n; ++i) b[i] = read();
  long long l = 0, r = 2000000005, ans;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    if (pd(mid)) {
      ans = sum + 2 * k * mid;
      l = mid + 1;
    } else
      r = mid - 1;
  }
  printf("%lld\n", ans);
  return 0;
}
