#include <bits/stdc++.h>
using namespace std;
const long long maxl = 500005;
long long read() {
  long long s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -w;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + (ch ^ '0');
    ch = getchar();
  }
  return s * w;
}
long long n, k;
long long a[maxl], b[maxl];
struct node {
  long long fi, se;
};
bool operator<(node xx, node yy) { return xx.fi > yy.fi; }
signed main() {
  n = read(), k = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= n; i++) b[i] = read();
  long long L = 0, R = 2e9;
  while (L <= R) {
    long long mid = (L + R) >> 1, cnt = 0, tot = 0;
    priority_queue<node> q;
    for (long long i = 1; i <= n; i++) {
      q.push((node){a[i] - mid, 0});
      long long val = b[i] + q.top().fi;
      if (val < 0) {
        tot += val;
        if (q.top().se == 0) cnt++;
        q.pop(), q.push((node){-b[i], 1});
      }
    }
    if (cnt == k)
      return cout << tot + k * mid << endl, 0;
    else if (cnt < k)
      L = mid + 1;
    else
      R = mid - 1;
  }
  return 0;
}
