#include <bits/stdc++.h>
template <class T>
void read(T &);
template <class T>
void write(const T &);
const int iinf = 2147483647;
const long long llinf = 9223372036854775807ll;
constexpr int N = 500005;
int a[N], b[N];
int n, k;
int main() {
  read(n), read(k);
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    read(b[i]);
  }
  long long l = 0, r = 2e9;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long ans = 0;
    std::priority_queue<std::pair<int, int> > pq;
    for (int i = 1; i <= n; ++i) {
      pq.emplace(-a[i], 0);
      int tmp = b[i] - mid - pq.top().first;
      if (tmp < 0) {
        ans += tmp;
        pq.pop();
        pq.emplace(b[i] - mid, 1);
      }
    }
    int cnt = 0;
    while (!pq.empty()) {
      cnt += pq.top().second;
      pq.pop();
    }
    if (cnt == k) {
      write(ans + cnt * mid), putchar('\n');
      return 0;
    }
    if (cnt < k) {
      l = mid + 1;
    } else {
      r = mid - 1;
    }
  }
  return 0;
}
template <class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while ((ch >= '0' && ch <= '9')) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}
